Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstructing query from dict not working #531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ybenitezf
Copy link

  • Updating the code in pydal/objects for reconstructing a Query object from a dict.
  • Fix for uploadfs.open with expect a unicode not a str

close #530

@ybenitezf
Copy link
Author

¿any one?

@@ -2172,14 +2172,15 @@ def build(self, d):
d.get("second", None))
left = right = built = None

if op in ("AND", "OR"):
op = op.upper()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this fix. But why change AND -> _AND?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the query is pickle to the session the operators and, or and not are prefixed with _, so: _AND, _OR and _NOT

In [1]: q = db(db.auth_user.id > 0) & (db.auth_user.id < 10)

In [2]: q
Out[2]: <Query (("auth_user"."id" < 10) AND <Set ("auth_user"."id" > 0)>)>

In [3]: q.as_dict()
Out[3]: 
{'_db': <DAL uri="sqlite://storage.sqlite">,
 'db': <DAL uri="sqlite://storage.sqlite">,
 'first': <Query ("auth_user"."id" < 10)>,
 'ignore_common_filters': False,
 'op': <bound method SQLiteDialect._and of <pydal.dialects.sqlite.SQLiteDialect object at 0x7f897554ff90>>,
 'optional_args': {},
 'second': <Set ("auth_user"."id" > 0)>}

In [4]: q.as_dict(flat=True)
Out[4]: 
{'first': {'first': {'fieldname': 'id', 'tablename': 'auth_user'},
  'ignore_common_filters': False,
  'op': 'lt',
  'optional_args': {},
  'second': 10},
 'ignore_common_filters': False,
 'op': '_and',
 'optional_args': {}}

Note to that the < is not prefixed with _. Actually all the operatos are lowercase, i just make then upper there for the sake of not making to many changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I am slow I still do not understand where do the '_' comes from?

@ybenitezf
Copy link
Author

There is a problem in this, LTE (<=) and GTE (>=) are not processed correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconstructing query from dict not working
2 participants