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

Unable to compare datetime attributes #737

Open
miversen33 opened this issue Feb 1, 2025 · 1 comment
Open

Unable to compare datetime attributes #737

miversen33 opened this issue Feb 1, 2025 · 1 comment

Comments

@miversen33
Copy link

miversen33 commented Feb 1, 2025

Hello Ponyorm team! I am running into an interesting issue, and its one that I suspect I am just missing something on.

Below is a test python script to replicate what I am seeing, but basically I cannot perform date time comparisons with ponyorm. I get an exception (included below the snippet)

from datetime import datetime

from pony import orm
from pony.orm import Required, db_session

db = orm.Database()

class Foo(db.Entity):
    insert_time = Required( datetime, default = datetime.now())
    key = Required(str)
    value = Required(str)

db.bind(provider = 'sqlite', filename = ':memory:')
db.generate_mapping(create_tables=True, check_tables=True)

with db_session:
    f = Foo(key = "hello", value = "world")
    a = Foo.select(lambda foo: foo.insert_time <= datetime.now())
    print(a)
Traceback (most recent call last):
  File "/tmp/test.py", line 18, in <module>
    a = Foo.select(lambda foo: foo.insert_time <= datetime.now())
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/core.py", line 4027, in select
    if args: query = entity._query_from_args_(args, kwargs, frame_depth=cut_traceback_depth+1)
                     ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/core.py", line 4401, in _query_from_args_
    return Query(code_key, inner_expr, globals, locals, cells)
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/core.py", line 5672, in __init__
    tree, extractors = create_extractors(code_key, tree, globals, locals, special_functions, const_functions)
                       ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 451, in create_extractors
    src = node.src = ast2src(node)
                     ~~~~~~~^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 75, in ast2src
    PythonTranslator(tree)
    ~~~~~~~~~~~~~~~~^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 89, in __init__
    translator.dispatch(tree)
    ~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 47, in dispatch
    translator.call(post_method, node)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 91, in call
    node.src = method(translator, node)
               ~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/miversen/git/spotify-playlist-exporter/venv/lib/python3.13/site-packages/pony/orm/asttranslation.py", line 220, in postCall
    args = [ arg.src for arg in node.args ] + [ kw.src for kw in node.keywords ]
             ^^^^^^^
AttributeError: 'NoneType' object has no attribute 'src'

What am I missing here?

Note, I did try just using integers instead (as I was able to do that in sqlite directly, and as called out in their documentation, sqlite3 doesn't have a concept of datetime anyway), but trying to save seconds after epoch gave me a different error (saying my integer was too big), even after setting the maximum to 32 (the biggest sqlite allows I guess?) and making it unsigned.

Edit:

Some potentially useful information

Python Version: 3.13.1
OS: Arch Linux
Ponyorm version: 0.7.19

@miversen33
Copy link
Author

Update: this issue is specific to python version 3.13.1. I tested with python 3.12.8 and its working just fine.

According to #729 python 3.13 is currently not supported so this makes sense. I am not going to close this out (feel free if you would like), as this issue does exist in 3.13.

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

No branches or pull requests

1 participant