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 #530

Open
ybenitezf opened this issue Apr 11, 2018 · 1 comment
Open

Reconstructing query from dict not working #530

ybenitezf opened this issue Apr 11, 2018 · 1 comment

Comments

@ybenitezf
Copy link

Is this not working any more ?

>>> q = (db.person.id == 1)
>>> db(q.as_dict(flat=True)).select()
  File "<string>", line unknown
SyntaxError: Operator not supported: eq

That is in a web2py shell, I mean is the same thing passing around the query in the session as a dict, is not ?

@ybenitezf
Copy link
Author

Looking at the code in

def build(self, d):

It seems that the value of op is expected to be uppercase, however:

>>> from pydal import DAL, Field
>>> db = DAL('sqlite://storage.db')
>>> db.define_table('thing',Field('name'))
<Table thing (id, name)>
>>> db.thing.insert(name='Chair')
1L
>>> query = db.thing.id > 0
>>> query.as_dict(flat=True)
{'second': 0, 'ignore_common_filters': False, 'optional_args': {}, 'first': {'fieldname': 'id', 'tablename': 'thing'}, 'op': 'gt'}
>>> db(query.as_dict(flat=True)).select(db.thing.ALL)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pydal/base.py", line 691, in __call__
    return self.where(query, ignore_common_filters)
  File "pydal/base.py", line 702, in where
    return Set(self, query, ignore_common_filters=ignore_common_filters)
  File "pydal/objects.py", line 2096, in __init__
    query = self.parse(query)
  File "pydal/objects.py", line 2167, in parse
    return self.build(self.dquery)
  File "pydal/objects.py", line 2228, in build
    raise SyntaxError("Operator not supported: %s" % op)
SyntaxError: Operator not supported: gt

You can see that query.as_dict() returns the value of op as lowercase.

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 a pull request may close this issue.

1 participant