Ben
but I'll try anyway to confirm
Alexander
Do you mean the problem is not that the object appeared mysteriously before model(**x) is called, but that model.get(...) could not find it? Do you pass the correct primary key to model.get(...)?
Ben
Yes exactly. Yes I even tried hardcoding it. And model.select() is empty
Ben
One thing that might be of interest, is that I actually have two databases, I import data from one and copy it to model. Maybe when I call commit() and rollback() it's only doing it on the first one?
Alexander
No, it should work with both databases
Ben
Is there anything I can log to help?
Ben
maybe model._database_._get_cache() ?
Alexander
You can print model._database_._get_cache().indexes
Alexander
or cache = model._database_._get_cache() print(cache.indexes[model._pk_attrs_])
Ben
defaultdict(<class 'dict'>, {})
Ben
cache.indexes[model._pk_attrs_] this is also empty
Alexander
The same checks are happens inside _get_from_identity_map_ when new object is created: cache = entity._database_._get_cache() pk_attrs = entity._pk_attrs_ cache_index = cache.indexes[pk_attrs] And they found the created objects. That means one of the following: * You check the cache for a different database * The object was created later, after the print that you added Are your model belongs to a correct database?
Alexander
As you are working with two databases, is it possible that you have two different model classes belonging to a different databases and use the wrong model during the model.get(...) call?
Ben
hmm
Ben
I'm using model on two consecutive lines, one to get and one to write, so I dont think so. Also it works when running it outside of the tests.
Ben
I will triple check
Ben
this makes no sense, something very cursed is happening. I'm printing the cache and the next line in model(**x) it's just checking it and it has changed somewhere in between
Ben
I will dig further and let you know if I figure it out
Ben
Is there any way the cache gets updated within the model(**x) call?
Alexander
Creating the model updates cache at the end. But it should happen later
Alexander
Is it possible that the overrided __init__ method of the model has some side effects?
Ben
It's not overriden
Ben
This is so weird, I print model._database_._get_cache().indexes[model._pk_attrs_] on the line right before model(**x) and it's empty
Ben
ok so actually I removed the first write of the model in the DB and it still happens
Ben
and a raw SQL query confirms that it does not exist in the DB
Alexander
Did you try this? If you can reproduce the failed test on your developer machine, you can find the line 4426 in pony.orm.core: if obj_to_init is None: obj = object.__new__(entity) And add the next line: if entity.__name__ == 'X' and pkval == (1,): assert False
Ben
I'll check if I can do that, currently its within a container thats rebuilt for each test run, so I would need to change the pony install within it
Ben
maybe I can monkeypatch the pony function instead haha
Alexander
You can do something like: from pony.orm.core import EntityMeta original = EntityMeta._get_from_identity_map_ def patched(entity, pkval, status, *args, **kwargs): obj = original(entity, pkval, status, *args, **kwargs) if entity == X and pkval == (1,): assert False return obj EntityMeta._get_from_identity_map_ = patched
Lucky
Hello, is there any info about migration tool, release, and async support?
Currently the second best option for doing Updates with ponyorm is the pony_up library.
Evan
hey guys there isn't a reflection tool to autoload table definitions from an existing database right?
El Mojo
hey guys there isn't a reflection tool to autoload table definitions from an existing database right?
Not with pony. There is one for sqlalchemy that you can execute and adapt the results afterwards
Evan
There are Pony inspect
Is pony inspect the same similar to reflection?
El Mojo
https://github.com/abetkin/pony-inspect You might also try this one. I didn't know about this project. Has some limitations but can be a good start
Hello Please I have a Cloud postgres DataBase How to Backup it to db file i want make some changes such as convert a field type from TEXT to Json
Evan
Can pony orm handle system versioning?
Jacob AKA Sartre
Data versioning for the db?
Evan
the below is what i meant with regards to system versioning https://docs.microsoft.com/en-us/sql/relational-databases/tables/temporal-tables?view=sql-server-ver15
Jacob AKA Sartre
i don't think pony supports this. neither postgre does AFAIK
Evan
ty
Harry
Hey all - it doesn't look like Pony supports traditional migrations. If that's the case how do I update the model?
Harry
Sorry just searched the chat channel and it looks like migrations are coming. And people are using dbmate to do thier migrations currently
Alexander
Hey. Tbh they aren't coming in near future. It is really hard for us to find time to work on such things as migrations. In current state migrations do work with PostgreSQL, but some bugs are known. I actually built one project using Pony Migrations with Flyway as migrations manager. If someone in community could help finishing migrations we probably will help with information needed. Even issues with migrations would be really helpful.
Mario
Hey guys, has someone tried to use pony with gevent and postgres? Apparently we are having a ProgrammingError caused by a select call when an async query is underway. The async is set on by gevent with the set_wait_callback of psycopg but I'm not sure if pony code designed to work that way
Alexander
Pony is not adapted for async at all. The only way to use Pony is - never interrupt db_session with any async call.
Alexander
https://docs.ponyorm.org/integration_with_fastapi.html#async-and-db-session
Mario
I mean async queries not python. Async calls
Alexander
Pony cannot do async anything
Alexander
Hi Mario! You can try this approach: https://stackoverflow.com/questions/34812942/psycopg2-copy-from-raises-asynchronous-programmingerror-with-sync-connection-in/37606536#37606536
Mario
Nice hint! Thank you much @metaprogrammer
Mario
https://github.com/ponyorm/pony/issues/564
Mario
@metaprogrammer what about this approach, i have tried and seems to be working. Substituting the pg pool by the class using the threaded connection pool so far is working fine. Any concerns about it?
Evan
hey guys does ponyORM support MSSQL? - looking at this link it seems like no? https://docs.ponyorm.org/database.html#binding-the-database-object-to-a-specific-database
MassiveBox
Hello, I've just installed Pony ORM and I'm testing it a bit. But I get an error when calling db.bind(provider='sqlite', filename='students.db'): "File "/home/massive/.local/lib/python3.9/site-packages/pony/orm/dbproviders/sqlite.py", line 5, in <module> import sqlite3 as sqlite ModuleNotFoundError: No module named 'sqlite3'" I've tried with pip install sqlite3 but it isn't found. I did install pony with pip successfully.
Alexander
Hi! sqlite3 module is part of a system library. https://docs.python.org/3/library/sqlite3.html It looks like your Python was compiled without sqlite3 for some reason
MassiveBox
Could be debian weirdness. Thanks! I'll try installing from another source.
Nikolay
Could be debian weirdness. Thanks! I'll try installing from another source.
Debian does like to cut standard python into parts. There's usually an apt package available to get the missing part back like python3-venv. Pretty sure modern debian doesn't cut sqlite3 from python3 though. I don't have a fresh debian box but I don't remember ever having issues with sqlite3 on my debian and ubuntu servers (except when compiling from source) and python3-bottle-sqlite only depends on python3.
Ben
Hello! One question, if I use flush() to get the ID of an object (to then send to another external service), am I guaranteed that: 1. If I commit the ID when committing will be the same, 2. If I rollback the object will be removed?
Alexander
Yeah, I think so.
Pedro
Hi, it's possible to generarte entities in Pony from database tables ? (some like reverser enginering)
Alexander
Maybe something like this could help https://github.com/abetkin/pony-inspect
Permalink Bot
Maybe something like this could help https://github.com/abetkin/pony-inspect
Permanent link to the abetkin/pony-inspect project you mentioned. (?)
Pedro
Thanks a Lot!!! All of you
Damiano
pony.orm.core.BindingError: Database object was already bound to SQLite provider db.bind('sqlite', 'users.sqlite3', create_db=True) db.bind('sqlite', 'groups.sqlite3', create_db=True) db.generate_mapping(create_tables=True) Is it possible to bind two different databases?
Bob
I think you need to use a second Database object
Damiano
I think you need to use a second Database object
Yes, I simply created another table instead of a new database file, by adding another class ("Class Table2(db.Entity):")
Saint
Hello, I want to use PonyORM with FastAPI. I follow the instructions, but I get an error pony.orm.core.BindingError: Mapping was already generated. Help me please. Picture1: https://ibb.co/JxhxXwb Picture2: https://ibb.co/R9vQzgk Picture3: https://ibb.co/n8NHWNp
Volbil
Not sure if this would help but who knows
Volbil
Also Pony doesn't play well with async code so uvicorn might be an issue