Alexander
It should work
Kaustubh
got it
Volbil
Hello, is there a way to make Set inside model return same result each time when program iterating over it?
Volbil
I tried to make @property with set.order_by inside but this doesn't work for some reason
Matthew
in a @property: select(x for x in X if x.y == self).order_by(...)
Anonymous
Has anyone gotten Pony working with the Nuitka python compiler?
Paŭlo
Hello, can someone help me with a number iterator?: https://stackoverflow.com/questions/69273770/simple-infinite-iterator-in-python
Matthew
This channel is only for pony related stuff
Anonymous
I tried to compile my script with Nuitka, but when Pony initializes - it ignores the custom primary keys that I defined in my models and opts to use the default ID variable (and the sequences that get created to support it). There are a couple of issues in both the Pony and Nuitka github repos from 2017, but they're not what I'm running into (maybe I haven't gotten far enough yet?)
Alexander
Pony relies on Python's possibility to modify locals of the different frame. When defining custom primary keys, Pony injects key information into the locals dict of the class frame, specifically it creates an _indexes_ list inside it and add a key to this list. It is possible that Nuitka did not allow modifying the locals of the previous frame, or class frame (which exists during the class creation) is processed differently in Nuitka. You can try manually create _indexes_ list inside class body before definition of primary key, maybe that will help
Anonymous
I'll give it a try, thanks!
Christian
Hi. I'm unable to catch TransactionIntegrityError with this code (only excerpt): from pony.orm.core import TransactionIntegrityError ... try: user = User() except TransactionIntegrityError: print('User already exists.')
Christian
Any ideas? I'm always getting the same error message: pony.orm.core.TransactionIntegrityError: Object <User Dolores Haze> cannot be stored in the database. IntegrityError: UNIQUE constraint failed: User.login_name
Christian
I can be wrong, but I think this error must be catched on db_session level
Sorry, the above is not the full code. It is within db_session.
Volbil
Sorry, the above is not the full code. It is within db_session.
Yes, that's what I mean, try to wrap db_session with try/except
Volbil
Any ideas? I'm always getting the same error message: pony.orm.core.TransactionIntegrityError: Object <User Dolores Haze> cannot be stored in the database. IntegrityError: UNIQUE constraint failed: User.login_name
I guess you can add validation before trying to create user with given login_name. Something like "if user with login_name exists -> return error/don't create user"
Christian
Hm. You might be onto something. Just tried really broad with except Exception as e: and it's also not catching it.
Christian
I guess you can add validation before trying to create user with given login_name. Something like "if user with login_name exists -> return error/don't create user"
Yeah, just did it that way, cheers. Still curious, why the error (or errors, rather - there seem to be three consecutive ones) are not caught at all.
Christian
Hey, thanks for the ideas!
Christian
I might try, when I'm back at code.
Anonymous
re: pony / nuitka. I'm using the estore.py example for testing. I tried creating the _indexes_ list in the class body. class Order(db.Entity): _indexes_ = list id = PrimaryKey(int, auto=True) ... It did not care for that. Traceback (most recent call last): File "/Users/liamr/git/nuitka-test/estore.py", line 46, in <module> class Order(db.Entity): File "/Users/liamr/git/nuitka-test/venv/lib/python3.9/site-packages/pony/orm/core.py", line 3791, in __init__ if attr.is_unique: indexes.append(Index(attr, is_pk=isinstance(attr, PrimaryKey))) TypeError: descriptor 'append' for 'list' objects doesn't apply to a 'Index' object
Alexander
You need to write: _indexes_ = [] instead
Anonymous
That just went back to the original error.. pony.orm.dbapiprovider.OperationalError: no such column: OrderItem.id I'm going to try a simpler program where the models just use the default PK
Anonymous
Yup. Inserts in simpler program seem to work ok. I can see about reorganizing my code, but you have other ideas about dealing the custom PKs, I'd welcome them selects, however.. Traceback (most recent call last): File "/Users/liamr/git/nuitka-test/mcomm.py", line 60, in <module> things = list(Hr.select(lambda hr: hr.uid == uid )) File "/Users/liamr/git/nuitka-test/venv/lib/python3.9/site-packages/pony/orm/core.py", line 4034, in select if args: query = entity._query_from_args_(args, kwargs, frame_depth=cut_traceback_depth+1) File "/Users/liamr/git/nuitka-test/venv/lib/python3.9/site-packages/pony/orm/core.py", line 4395, in _query_from_args_ else: assert False # pragma: no cover AssertionError
Jan
Hello there, maybe a stupid question, but I tried to gather information from the docs and don't know exactly what to look for. I want to check, if a referenced object actually exists in the database and is not just a phantom object created by PonyORM, preferably by not writing using explicit SQL-queries. Assume the following scheme: class A(db.Entity): primKey = PrimaryKey(int) data = Optional(int) class B(db.Entity): primKey = PrimaryKey(int) aObj = Optional(A) Let's say my database is badly configured and does not check for foreign keys to be valid. Let one A-entry A=(1, 0) and one B-entry B=(1, 42). I expected the following statement to yield None: B.get(primKey=1).aObj This however is not the case. Only as soon as I try to access the data field of the A-instance, I receive an exception of the phantom object having disappeared. I tried to check if the A-instance exists by using A.get(primKey=42) and sure enough, I get a result, as one B-instance is referring to an A-instance using said key. Is there any easy way, without correctly setting up the database to correctly use foreign keys, to check if the A instance really exists? Or perhaps to entirely disable this feature? Maybe there is something very obvious I am missing, sorry if this is the case. Thank you!
Jan
Yes, this is what I am currently doing, thank you :) Was just wondering if there was a more elegant solution.
Christian
I don't see how you could know if the database is working without trying it.
Lucky
Could you guys please have a look at the pull request with the simpler Enums again? That would really improve working with those.
Lucky
Because if I remember right, last time it looked quite good in the review. But for some reason we didn't end up merging it. However I don't see any risk associated with the existing code, only if one chooses to use Enums now that would be any risk associated. Which I think is low anyway - just the typical "yeah it's new code, there could be errors in that"
Lucky
Never mind I just read issue 502 once more, and there is still something wonky with the MySQL database.
Volbil
If Pony tests pass, it should be as easy as adding new version to config
Christian
@Volbil Unfortunately, it's not as easy as adding a new version to the list. See this issue here: https://github.com/ponyorm/pony/issues/598
Alexander
I think it will take one week to implement Python 3.10 support. I expect to release a new version of Pony with Python 3.10 support next week.
Alexander
Not in the near future, proper async ORM should store loaded data differently (not using IdentityMap), but we can probably do PonyORM a bit more async-friendly.
Lucky
Not in the near future, proper async ORM should store loaded data differently (not using IdentityMap), but we can probably do PonyORM a bit more async-friendly.
Hey, I'm also interested in that. Maybe we could stick our heads together, had a lot of fun doing async stuff recently.
Alexander
Sure, let discuss it a bit later, at first I need to implement an urgent fixes for Python 3.10 compatibility
Lucky
sure.
Lucky
Here is what I use for an async posgres database. I mostly use Class.get(id=123) anyway, and those 4 complex queries I can write with raw sql. Table creation and migration is manual too, but so are migrations with pony currently anyway. Licence: 1. I'm not liable, 2. If you midify it, make the modification open source.
Lucky
Example for that.
Lucky
(because of slowmode I can't send them as a group, lol)
Alexander
Looks pretty good, actually :)
Lucky
https://github.com/luckydonald/cheap_orm/blob/mane/cheap_orm.py
Permalink Bot
https://github.com/luckydonald/cheap_orm/blob/mane/cheap_orm.py
Permanent link to the file cheap_orm.py mentioned. (?)
Lucky
There you go
Lucky
And the example is https://github.com/luckydonald/cheap_orm/blob/mane/cheap_orm_example.py
Permalink Bot
And the example is https://github.com/luckydonald/cheap_orm/blob/mane/cheap_orm_example.py
Permanent link to the file cheap_orm_example.py mentioned. (?)
Lucky
I think creating a full pony on python 3 type annotations would be awesome
Karsten
@Alexander Kozlovsky Hello, when is Pony available for Python 3.10 ? pip exits with an error message. best regards Karsten
Karsten
October 25
October 2025 or 25. October ? 😅
Alexander
I hope the latter :)
Ivan
Hi to all :) Can somebody help me please? The question is how to handle case when I have existing database with relation many-to-many, so I have table A and table B, as well as table C which is handling this relation of A and B, if understood corretcly, pony creates extra table for manytomany, what I should do?
Alexander
class A(db.Entity): _table_ = "tableA_name" # you can specify table name if necessary id = PrimaryKey(int) foo = Required(str) b_set = Set("B", table="tableC_name", columns="a_id") class B(db.Entity): _table_ = "tableB_name" id = PrimaryKey(int) bar = Required(str) a_set = Set(A, columns="b_id")
Ivan
will try this solution Thank you, @metaprogrammer Maybe you can answer one more question, as I noticed, I must to use db.generate_mapping() every time, but is there convinient way to work with db insted of using db.generate_mapping(create_tables=False), when tables exists
Alexander
If you have existing db, you can just skip create_tables=False db.generate_mapping()
Ivan
Ok, thanks a lot)
Jan
Hey, I know I ask a bunch of questions (:D), but how would I create an entity object from a JSON dictionary, when some attributes are non-optional? So for instance: class A(db.Entity): a = PrimaryKey(int, auto=True) b = Required(str) c = Optional(str) @db_session create_a(attribute_dict): obj = A() for attr in attribute_dict.keys(): setattr(obj, attr, attribute_dict[attr]) This does not work, as the constructor of A is not provided with a value for b. A solution I would be happy with is the creation of the object and checking for required attributes on commit and not on calling the constructor: obj = A() obj.b = "foo" Is this possible? The background of this is, that I have a bunch of entities but would rather not create a huge case-distinction for each type and add the required parameters in that way, and rather leave it generic. A reverse function for the JSON conversion ".to_dict()" would resolve this issue for me (something like .from_dict(attribute_dict)). Does something like this exist and I just can't find it in the docs? Thanks.
Jan
The only idea I have left is to declare every non-primary field as optional in the PonyORM declaration and catch commit errors, when an actually required attribute is not set. I feel like this is not the right approach though
Alexander
Hi! Right now, this is not supported. As a workaround, you can specify default values for required attributes and override their values after the object instance creation.
Jan
Oh yes, this actually solves it really easily for now. Thank you!
Alexander
@Alexander Kozlovsky Hello, when is Pony available for Python 3.10 ? pip exits with an error message. best regards Karsten
Sorry, support for Python 3.10 is not ready yet. I hope we will have it a week later
Karsten
it's okay!
Christian
Hi, I'm getting some really strange stuff with Pony on Azure, when the app should start up: 2021-10-27T07:04:45.401183937Z: [ERROR] File "/tmp/8d999157e96a00b/antenv/lib/python3.8/site-packages/pony/thirdparty/compiler/transformer.py", line 842, in com_node 2021-10-27T07:04:45.401189037Z: [ERROR] return self._dispatch[node[0]](node[1:]) 2021-10-27T07:04:45.401197537Z: [ERROR] File "/tmp/8d999157e96a00b/antenv/lib/python3.8/site-packages/pony/thirdparty/compiler/transformer.py", line 617, in testlist_comp 2021-10-27T07:04:45.401203237Z: [ERROR] assert nodelist[0][0] == symbol.test 2021-10-27T07:04:45.401208137Z: [ERROR] AssertionError 2021-10-27T07:04:45.418676351Z: [INFO] 172.16.2.1 - - [27/Oct/2021:07:04:45 +0000] "GET /admin/ HTTP/1.1" 500 290 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0" 2021-10-27T07:05:07.001822819Z: [ERROR] [2021-10-27 07:05:06 +0000] [36] [INFO] Handling signal: term 2021-10-27T07:05:07.013929229Z: [ERROR] [2021-10-27 07:05:06 +0000] [61] [INFO] Worker exiting (pid: 61) 2021-10-27T07:05:07.415824241Z: [ERROR] [2021-10-27 07:05:07 +0000] [36] [INFO] Shutting down: Master
Christian
Any idea? Anybody?
Christian
It seems to fail on /thirdparty/compiler/transformer.py:617
Christian
I'm running Python 3.8.12. I'm inclined to believe that it's because of (a) general azure yuckiness or (b) some server-side misconfiguration. Just curious, if someone has seen something similar.
Alexander
Is it full traceback? I think the error happens during some query translation. Maybe looking at the query code can give a hint for a reason for the error.
Christian
Solved, it couldn't create the tables in the db. Whatever the above has to do with that.
Christian
This looks really promising, concerning FastAPI: https://github.com/tiangolo/sqlmodel
Permalink Bot
This looks really promising, concerning FastAPI: https://github.com/tiangolo/sqlmodel
Permanent link to the tiangolo/sqlmodel project you mentioned. (?)
Christian
It marries Database and Pydantic Models, which makes for quite a bit of duplicate code at the moment.