0

sqlite3Pony orm (バージョン 0.7.1、python 3.6.0) を使用してアクセスしているデータベースがあります。

列/フィールドの 1 つは期間 ( timedelta) です。期間が指定された時間未満のすべての行を選択しようとしています。

私がやっていることの最小限の例:

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) 

これを実行すると、AssertionError: delta

pony.orm.select(x for x in TestTime if x.td < delta)構文を使用してクエリを実行すると、同じエラーが発生します。

それが役立つ場合の完全なトレースは次のとおりです。

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

私は何か間違ったことをしていますか、それとももっと良い方法がありますか?

4

1 に答える 1