Skip to content

The wrap method in Query breaks return_models #47

Description

@JockeTF

Using the wrap method in Query breaks the return_models functionality of the select method.

>>> q = Query().from_table(Rating).limit(1).wrap()
>>> q.select(return_models=True)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-afd37124e1a1> in <module>()
----> 1 q.select(return_models=True)

/usr/local/lib/python3.4/dist-packages/querybuilder/query.py in select(self, return_models, nest, bypass_safe_limit, sql, sql_args)
   1555             # create models if needed
   1556             if return_models:
-> 1557                 model_class = self.tables[0].model
   1558                 new_rows = []
   1559                 for row in rows:

AttributeError: 'QueryTable' object has no attribute 'model'

It's possible to work around the issue by assigning the model attribute manually.

>>> q = Query().from_table(Rating).limit(1).wrap()
>>> q.tables[0].model = Rating
>>> q.select(return_models=True)
[<Rating: Rating object>]

Using the Query without wrapping it works as expected.

>>> q = Query().from_table(Rating).limit(1)
>>> q.select(return_models=True)
[<Rating: Rating object>]

Thanks for the awesome library, it has saved me a lot of effort!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions