Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-175

Expansion on as_class option

    • Type: Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I tried returning data as custom class, but ran into problem where
      nested dictionary would all be type of custom class I assigned.
      It would be nice to have an option to only have as_class declared class to
      be used for base level and not recursively.
      Currently I modified code of bson._init_.py

      def _elements_to_dict(data, as_class, tz_aware):
          result = as_class()
          while data:
              (key, value, data) = _element_to_dict(data, as_class, tz_aware)
              result[key] = value
          return result
      to
      def _elements_to_dict(data, as_class, tz_aware):
          result = as_class()
          while data:
              (key, value, data) = _element_to_dict(data, dict, tz_aware)
              result[key] = value
          return result
      

      It's working pretty well this way, but it would be nice to have some way to
      switch it.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            yuta Yuta Araki
            Votes:
            10 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: