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

Assertion error trying to query on timedelta columns #249

Closed
tpoliaw opened this Issue Mar 24, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@tpoliaw
Copy link

tpoliaw commented Mar 24, 2017

I am trying to select rows based on a timedelta field and getting an AssertionError suggesting the timedelta is not a time (which it shouldn't be).

Steps to reproduce:

import pony.orm                                                                    
from datetime import timedelta                                                     

db = pony.orm.Database()                                                           

class TestTime(db.Entity):                                                         
    id = pony.orm.PrimaryKey(int, auto=True)                                       
    td = pony.orm.Required(timedelta)                                              

db.bind('sqlite', ':memory:', create_db=True)                                      
db.generate_mapping(create_tables=True)                                            

if __name__ == "__main__":                                                         
    with pony.orm.db_session:                                                      
        tt1 = TestTime(td=timedelta(seconds=12))                                   
        tt2 = TestTime(td=timedelta(seconds=18))                                   
        db.commit()                                                                

    delta = timedelta(seconds=15)                                                  
    with pony.orm.db_session:                                                      
        TestTime.select(lambda x: x.td < delta)

Expected:

No errors. Query to return tt1.

Actual behaviour:

Traceback (most recent call last):
  File "ponytd.py", line 23, in <module>
    TestTime.select(lambda x: x.td < delta)
  File "<string>", line 2, in select
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/utils/utils.py", line 58, in cut_traceback
    return func(*args, **kwargs)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/core.py", line 3596, in select
    return entity._query_from_args_(args, kwargs=None, frame_depth=3)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/core.py", line 3943, in _query_from_args_
    return Query(code_key, inner_expr, globals, locals, cells)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/core.py", line 5087, in __init__
    translator = translator_cls(tree, extractors, vartypes, left_join=left_join)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 269, in __init__
    translator.dispatch(if_)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 82, in dispatch
    return ASTTranslator.dispatch(translator, node)  # default route
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/asttranslation.py", line 29, in dispatch
    translator.dispatch(child)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 82, in dispatch
    return ASTTranslator.dispatch(translator, node)  # default route
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/asttranslation.py", line 24, in dispatch
    stop = translator.call(pre_method, node)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 135, in call
    reraise(exc_class, exc, tb)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/utils/utils.py", line 85, in reraise
    try: raise exc.with_traceback(tb)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 125, in call
    try: monad = method(node)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 649, in preCompare
    translator.dispatch(right)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 83, in dispatch
    translator.call(translator.dispatch_external, node)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 135, in call
    reraise(exc_class, exc, tb)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/utils/utils.py", line 85, in reraise
    try: raise exc.with_traceback(tb)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 125, in call
    try: monad = method(node)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 119, in dispatch_external
    monad = translator.ParamMonad.new(translator, t, (varkey, None, None))
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 1646, in new
    result = cls(translator, type, paramkey)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 1654, in __init__
    Monad.__init__(monad, translator, type)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 1006, in __init__
    monad.mixin_init()
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 986, in wrapper
    return method(monad, *args, **kwargs)
  File "/home/user/.local/share/virtualenvs/test-Tqz3IJV7/lib/python3.6/site-packages/pony/orm/sqltranslation.py", line 1310, in mixin_init
    assert monad.type is time
AssertionError: delta

@kozlovsky kozlovsky closed this in 8402428 Dec 2, 2017

kozlovsky added a commit that referenced this issue Jul 23, 2018

Pony ORM Release 0.7.4 (2018-07-23)
# Major features

* Hybrid methods and properties added: https://docs.ponyorm.com/entities.html#hybrid-methods-and-properties
* Allow to base queries on another queries: `select(x.a for x in prev_query if x.b)`
* Added support of Python 3.7
* Added support of PyPy
* `group_concat()` aggregate function added
* pony.flask subpackage added for integration with Flask

# Other features

* `distinct` option added to aggregate functions
* Support of explicit casting to `float` and `bool` in queries

# Improvements

* Apply @cut_traceback decorator only when pony.MODE is 'INTERACTIVE'

# Bugfixes

* In SQLite3 `LIKE` is case sensitive now
* #249: Fix incorrect mixin used for Timedelta
* #251: correct dealing with qualified table names
* #301: Fix aggregation over JSON Column
* #306: Support of frozenset constants added
* #308: Fixed an error when assigning JSON attribute value to the same attribute: obj.json_attr = obj.json_attr
* #313: Fix missed retry on exception raised during db_session.__exit__
* #314: Fix AttributeError: 'NoneType' object has no attribute 'seeds'
* #315: Fix attribute lifting for JSON attributes
* #321: Fix KeyError on obj.delete()
* #325: duplicating percentage sign in raw SQL queries without parameters
* #331: Overriding __len__ in entity fails
* #336: entity declaration serialization
* #357: reconnect after PostgreSQL server closed the connection unexpectedly
* Fix Python implementation of between() function and rename arguments: between(a, x, y) -> between(x, a, b)
* Fix retry handling: in PostgreSQL and Oracle an error can be raised during commit
* Fix optimistic update checks for composite foreign keys
* Don't raise OptimisticCheckError if db_session is not optimistic
* Handling incorrect datetime values in MySQL
* Improved ImportError exception messages when MySQLdb, pymysql, psycopg2 or psycopg2cffi driver was not found
* desc() function fixed to allow reverse its effect by calling desc(desc(x))
* __contains__ method should check if objects belong to the same db_session
* Fix pony.MODE detection; mod_wsgi detection according to official doc
* A lot of inner fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.