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(...)
Volbil
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.')
Volbil
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
Volbil
Christian
Hm. You might be onto something. Just tried really broad with except Exception as e: and it's also not catching it.
Christian
Vitaliy
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!
Christian
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!
@janerjak Hi, this has been sitting here for a while: Would working around this with a try / except block work, where you explicitely use flush() or commit() and see if it throws an error.
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
Volbil
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.
Volbil
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
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
Lucky
There you go
Lucky
And the example is https://github.com/luckydonald/cheap_orm/blob/mane/cheap_orm_example.py
Permalink Bot
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
Alexander
Karsten
October 25
October 2025 or 25. October ? 😅
Alexander
I hope the latter :)
Karsten
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
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
Karsten
it's okay!
Elraro
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
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
Christian
It marries Database and Pydantic Models, which makes for quite a bit of duplicate code at the moment.