Alexander
Oh yeah I see PR. It seems that some decompiling work needed
Volbil
Also I checked on my own and pony seams to work fine in my project
Volbil
Still, some edge cases may occur so it need testing
Alexander
https://github.com/ponyorm/pony/blob/orm/pony/orm/decompiling.py#L628 These lines are decompiling tests
Permalink Bot
Anonymous
Hello. Does pony handle database restarts gracefully? Whenever postgres gets restarted, pony raises an OperationalError with the message "terminating connection due to administrator command. server closed the connection unexpectedly". Is there anyway of ensuring the connection is operational?
Alexander
Hi scruffy! Pony should handle database restart gracefully. Can you show the traceback?
Anonymous
Hi Alexander
Anonymous
Sure! I've pasted it here: https://hastebin.com/ekireyuyor
Alexander
Can you catch this exception and check the value of e.original_exc.pgcode?
Alexander
Pony expects that if the exception type is OperationalError and exc.pgcode is None, then the server closed connection unexpectedly and Pony should try to re-open connection I suspect that in your case pgcode value of the original psycopg2 exception is not None
Aleksey
Hello!
Aleksey
What about migrations?
Aleksey
Here is old news: https://blog.ponyorm.org/2019/03/19/pony-orm-migrations/
Anonymous
Hi Alexander. I managed to catch the value of e.original_exc.pgcode
Anonymous
It's a string: 57P01
Anonymous
which corresponds to the error code raised by psycopg2
Anonymous
for the AdminShutdown exception
Kyle
Hi, gn
Kyle
Does with db_session: prefetch one to many relationships?
Kyle
I would like to have it prefetched on entity get()
El Mojo
Hi guys! Do any of you have experience with pony/fastapi?
Alexander
Yeah, I'm currently working with this stack
El Mojo
Yeah, I'm currently working with this stack
So any recommendations on how to to use it with pony? Regarding async, etc.
Alexander
Yeah. Don't use db_session decorator, use db_session context manager for wrapping lines of code that really works with database and are not interrupted by any async calls
Alexander
So you make small transactions and want to be sure they wont be paused by switching async context
Alexander
Don't use async calls inside with db_session code
El Mojo
OK thanks, dependencies too?
Alexander
with db_session: A() await func() <-- that will lead to error B() Use smaller transactions with db_session: A() await func() with db_session: B()
El Mojo
OK great! Thank you very much. Any news regarding new versions supporting async?
Alexander
Yeah, we decided to switch from threading.Local to ContextVar, that probably will fix this issue. Once we have a free time from our main job. We plan to make it really soon.
El Mojo
Hey great thanks, that would be great. I'm planning to deploy a website the next month, so I'll wait for the update 🙂
Anonymous
Pony expects that if the exception type is OperationalError and exc.pgcode is None, then the server closed connection unexpectedly and Pony should try to re-open connection I suspect that in your case pgcode value of the original psycopg2 exception is not None
Hi Alexander. I've checked the value of e.original_exc.pgcode and, as you suspected, it is not None but the string "57P01". Is there any possible solution that I could use of?
Alexander
Hi Alexander. I've checked the value of e.original_exc.pgcode and, as you suspected, it is not None but the string "57P01". Is there any possible solution that I could use of?
Hi scruffy! We just released PonyORM 0.7.14 which supports Python 3.9. This release contains fix for the problem that you described as well. You can try and check if pony reconnects automatically after the server restart now
Kyle
Hello
Kyle
Good evening
Kyle
Can I update field with relation just by id?
Kyle
It would be good if I don't have to query it everytime
Anon
Does anyone know what can be done to prevent a large cache size besides adding strict=True to the db session? I've got an application that see about 6GB of daily net IO and the cache size seem to grow to about 700MB. I've already set strict=True to all the db sessions.
Alexander
Do you have long-lived db sessions?
Anon
I will have another look, but there shouldn't be any, I'm creating a new db session for each request to the application.
Alexander
Then the cache should be cleared after each request
Alexander
Is it async application?
Anon
Indeed, that's what I thought.
Anon
partly yeah
Anon
I'm using a thread pool to make it "async"
Alexander
Are you sure you don't have`await` calls inside db_session?
Anon
yeah
Anon
all the code inside db_session will be sync
Anon
Will have another look to make sure though
Alexander
Can I update field with relation just by id?
Yes, you can, in that case Pony will not load the object with this id and will assume that is already presented in the database
Anon
Yeah, it's all sync, also, I wouldn't be able to call the function using the thread pool executor if it wasn't. Hmm will check if there are any profiling tools I can use to check.
Anon
thanks :)
RdfBbx
Hello! Tell me please, can I use PonyORM with Discordpy async library?
Kyle
Good morning
Kyle
You can use https://tortoise-orm.readthedocs.io/en/latest/ so it stays async
Kyle
You may also use pony and run function with db operation in run_in_executor using a threadpool but I don't recommend it
Kyle
@metaprogrammer Hi, is there a way I can set cascade_update on a set?
Alexander
@metaprogrammer Hi, is there a way I can set cascade_update on a set?
Pony does not use cascade_update at all, as Pony considers primary keys as immutable. You can create table manually with cascade_update and specify its name to Pony
Kyle
I see
Kyle
Thanks
Igel
i have a .sql file i read in, and do db.execute(line) .. i get ValueError exceptions.. the query insert also escapes json blobs quotes etc (relevant?) but 90% of everything else is fine
Igel
i remove the blobs, no diff..
Alexander
Does you sql contain $ signs?
Igel
yes!
Igel
makes sense
Alexander
Replace it to $$
Igel
kickass aK.. thanks!
Alexander
Or use low-level sqlite connection.execute() method
Igel
i use mysql bind, with execute...
Igel
i dont want to parse this makes things difficult
Alexander
I think you can do line = line.replace('$', '$$') without parsing or connection = db.get_connection() connection.execute(line)
Igel
okay i use connection.query(line) and its perfecto 👍
Vitaliy
Hello @metaprogrammer! Is there a way to compare timestamps with date/datetime in queries? For example by coercing one to another?