Alexander
Or, if you want to combine set in query, you can do: cats = [cat1, cat2] select(p for p in Product if p.category in cats)
Alexander
Or, if a relation is many-to-many, that is, a single product can belong to multiple categories, you can write cats = [cat1, cat2] select(p for p in Product if exists(cat for cat in p.categories if cat in cats))
Muhammed
Obviously I have a category class with subcategories. In the sub-categories, it is again category class. I want to select all products in one category and in subcategories
Muhammed
Or, if you want to combine set in query, you can do: cats = [cat1, cat2] select(p for p in Product if p.category in cats)
With this method, I must add all sub-categories to a list and make a selection with the help of this list.
Muhammed
Is this the best way for me?
Alexander
Do each product belongs to a single subcategory, or to multiple unrelated subcategories?
Muhammed
Each product has a only one category
Evgeniy
Hello! Please help us solve the problem. For one of the models, I use the custom method init(). It is passed information for creating a new instance of the model, plus some additional information that is not involved in initialization. The base init() is called via super(). So, I have 2 situations: 1. I call init() and a new entity is created; 2.I call init() and an error occurs in Pony ORM: AttributeError: _session_cache_. In both cases, exactly the same data is passed to super().init(). only the side data that is not directly involved in object initialization differs. What is the problem?
Jim
Is the new migration-dev branche testable ? Is there some doc ?
Alexander
It has some work to do
Evgeniy
File "/Users/out-blinov-e/Desktop/Projects/proza_new/lib/logger.py", line 40, in async_wrapper result = await func(*args, **kwargs) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 610, in new_gen_func output = wrapped_interact(iterator) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 596, in wrapped_interact rollback_and_reraise(sys.exc_info()) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 370, in rollback_and_reraise reraise(*exc_info) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/utils/utils.py", line 95, in reraise try: raise exc.with_traceback(tb) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 585, in wrapped_interact output = interact(iterator, input, exc_info) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 558, in interact return next(iterator) if input is None else iterator.send(input) File "/Users/out-blinov-e/Desktop/Projects/proza_new/handlers/new_post.py", line 90, in post post = Post(form, cover, categories, tags) File "/Users/out-blinov-e/Desktop/Projects/proza_new/models/post.py", line 37, in __init__ super(Post, self).__init__(**form) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 4695, in __init__ avdict[attr] = attr.validate(val, obj, from_db=False) File "/Users/out-blinov-e/Desktop/Projects/proza_new/virt/lib/python3.7/site-packages/pony/orm/core.py", line 2222, in validate if cache is not val._session_cache_:
Matthew
@metaprogrammer I have notied that the AssertionError`s are coming immediately after OptimisticCheckError`s in the same process. Is the only reason for the `OptimisticCheckError another process deleting an object which the session is tracking?
Jim
By the way did you try @join_captcha_bot against spam ?
Alexander
We cant grant admin permissions here so...
Nikolay
We cant grant admin permissions here so...
Can't as in "Can't afford to" or as in "Lost access to creator account and no one has add admins permission"
Alexander
Second one
Alexander
We have admin permissions, but can't grant them
Alexander
Because the original account was lost due to inactivity, and it was before Telegram started to warn in advance about this potential problem
yuanmeng
Why I get select() got an unexpected keyword argument when i use Param_G.select(tt=1) and i define it class Param_G(db.Entity): tt = Required(float) gm = Required(float) gc = Required(float) a = Required(float) b = Required(float) c = Required(float) d = Required(float) e = Required(float) f = Required(float)
v4ldevrr4m4
Hello Everybody , nice to meet you . I am from Panama , I have been using another tool in my projects but today begin to analize another ORM and I can see that POny have a great comunnity
Alexander
You are welcome! :)
v4ldevrr4m4
Saddly my main projects today are implementing MSSQL :(
Alexander
MS SQL is not supported yet by PonyORM
v4ldevrr4m4
YES I read that. Exist any documentation that justify that issue?
Alexander
There are no specific problems with adding MS SQL support, we just need to finish migrations at first
Ben
Hello all! Quick question because I'm reading conflicting information and would like clarification. When using DECIMAL type with SQLite, does pony use the SQLite NUMERIC type or does it stores it as text? Is there a significant performance penalty compared to float?
Alexander
Hi! At this moment Pony declares decimal column in SQLite as DECIMAL, and this is a bug. While Pony stores decimal values to SQLite as a text, SQLite treats DECIMAL column as a column with NUMERIC affinity, and converts string back to number value. We need to change column type declaration for Decimal column in SQLite to something like DECIMALTEXT to force text affinity #todo
Alexander
At this moment you can manually declare column like mycolumn = Optional(Decimal, sql_type='DECIMALTEXT') to fix this problem
Ben
why would you want to force TEXT affinity?
Alexander
To avoid loss of precision, because SQLite store values with the NUMERIC affinity as a floating-point numbers with double precision
Ben
aaah damn
Alexander
The point of Decimal type is to not use floating-point binary format
Ben
that is totally silly
Ben
why would sqlite do that
Ben
this is insane
Alexander
SQLite has some strange philosophy regarding types
Alexander
I agree this is silly
Alexander
It's a standard SQLite behavior. I think it is better to fix it and store Decimal values in textual form in SQLite. But this will lead to other difficulties, like, ORDER BY will not work as expected for numbers. So, correct "fix" should include some non-trivial changes, like, sometimes automatically cast decimal values from strings to floating-point numbers in SQLite (in ORDER BY at least)
Matthew
Is there a way to print/access cache.saved_objects from user code? I want to see why it is not empty, and there is an AssertionError when commiting.
Matthew
Matthew
I think this probably is a bug in my code, not pony
Alexander
Maybe it is a bug in your code, but it is a bug in pony code too, because assertion errors are not intended to be seen by a user, they are basically "this should never happen" checks To check saved_objects you can do cache = db._get_cache() # inspect cache.objects_to_save I suspect that the reason for the bug is some complex code in your before_XXX hooks
Matthew
ok thank you, I’ll monitor using that snippet and see what comes up
Alexander
Thanks!
Matthew
I suspect it is related to an OptimisticCheckError' that i’m also getting, which makes no sense
Matthew
“object was deleted outside of current transaction”
Matthew
but i am very careful to only ever do background processing in one process at a time, for a given account
Matthew
but we’ll see 🙂
Matthew
There are multiple DataSnapshots in the objects_to_save
Matthew
Should I only be checking objects_to_save right before the commit happens?
Alexander
it should be cleared on flush() (that is, before any query)
Alexander
So, probably yes
Matthew
If I am calling multiple functions which do queries, should I check objects_to_save before / after each function?
Alexander
I think you can modify this line in pony code from assert not cache.saved_objects to assert not cache.saved_objects, cache.saved_objects
Matthew
As an attempted fix?
Alexander
No, as a way to see saved_objects content when it should be empty Maybe it will give some hint
Matthew
oh, will it then show up in the tracebacks?
Alexander
yes
Matthew
good idea, I’ll do it
Matthew
That worked:
Matthew
AssertionError [(FacebookDataSnapshot[461968], 'deleted'), (FacebookDataSnapshot[461969], 'deleted'), (FacebookDataSnapshot[461970], 'deleted'), (FacebookDataSnapshot[462579], 'deleted'), (FacebookDataSnapshot[462580], 'deleted'), (FacebookDataSnapshot[462581], 'deleted'), (FacebookDataSnapshot[462698], 'deleted'), (FacebookDataSnapshot[462699], 'deleted')]
Matthew
does that mean those objects were deleted in the current transaction?
Alexander
It seems so
Alexander
Maybe I can fix it...
Anonymous
Hello - new to PonyORM and have a question about sessions.
Alexander
Hi! You are welcome!
Anonymous
Hi Alexander
Anonymous
Thanks!
Anonymous
I have an entity, of which I need to create probably many thousands of instances (let's call it a measurement.). I do so in exactly one place in the code, and I use with db_session where I create the object. Each new object must have one item identical, stream_id. However, when I create the new object, I get an error saying I can't unlink the entity because it's required.
Anonymous
So, it looks like this: def proc_emit(self, topic, record): super().proc_emit(topic, record) with db_session: # my_stream = Stream.get(stream_id=self.db_stream.stream_id) meas = LabInst_Fluke7060_Refridge_Bath(time=record['Timestamp'], BathTemp=record['Temp'], stream=self.db_stream.stream_id)
Anonymous
First time through, it works perfectly. Second time through, it bonks with this message: pony.orm.core.ConstraintError: Cannot unlink LabInst_Fluke7060_Refridge_Bath[5] from previous Stream['5cb100f4-57e1-4ee9-accc-06d2a4a167e0'] object, because Measurement.stream attribute is required
Anonymous
I guess I expected that the entity would commit and garbage collect after leaving the function? So the next time through it would create a new entity.
Alexander
It seems that the relationship between Stream and LabInst_Fluke7060_Refridge_Bath entities is wrong. Can you show model definitions for these entities? (It is enough to see definitions of Stream.meas and LabInst_Fluke7060_Refridge_Bath.stream)
Anonymous
Ok
Anonymous
Is there a formatting instruction for Telegram so it doesn't look so ugly?