Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-105

"TypeError: object of type 'NoneType' has no len()" in stream_to_handler

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.6
    • Affects Version/s: 0.5
    • Component/s: asyncio
    • Labels:
      None

      The stream_to_handler() function streams the contents of a GridFS file to an HTTP client, using a tornado.web.RequestHandler. Hence it's Tornado-specific, but I implemented and tested it framework-agnostically to keep the door open for an asyncio equivalent feature (MOTOR-92).

      Motor's framework-agnostic way to stream chunks from a GridFS file is:

      while written < self.length:
          chunk = yield self._framework.yieldable(self.read(self.chunk_size))
          # ... etc ...
      

      Yury Selivanov optimized how asyncio coroutines resolve Futures to values (pull 289) in a way that broke Motor's framework-compatibility layer starting in Python 3.4.4 and 3.5.1.

      stream_to_handler, and any other Motor function I write from now on that resolves a Future to a value, must resolve it in two steps:

      while written < self.length:
          f = self._framework.yieldable(self.read(self.chunk_size))
          yield f
          chunk = f.result()
      

      This is a minor bug since it only broke in asyncio, where this function won't be useful until and unless I implement MOTOR-92.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: