Volbil
Check if this file doesn't have generate_mapping there
Volbil
Maybe you trying to run it twice in your code
Volbil
sandi
Is there an easy way to convert a Pony object to a marshmallow Schema
sandi
Or in generell to get a Schema of the object
Ben
I'm getting an error that seems to come from within Pony
Ben
it is very strange as it happens consistently in my production environment but never when I test locally
Ben
also it doesnt seem like it can be possible
Ben
query_key cannot both be None and not None
Alexander
It says that cache.query_results is None.
But error seems strange
Ben
yes you're right
Ben
still I have no idea why it happens. Any idea on how I can fix it?
Alexander
Not close to PC rn, but maybe pony has test based on checking for query_result to be None.
Maybe query was not executed yet?
Ben
I had a very similar error due to empty query result on that same server
Alexander
Whats your query in 2nd case?
Alexander
I think we should wait for Alexander K, I've never seen this before
Ben
the other query is: self.contract_events.filter(
lambda e: e.type in event_types and time >= e.time and e.time >= from_time
).order_by(db.ContractEvent.time)
Ben
the issue seems to be here in Pony code, it is setting query_results to None
Alexander
I think it resetting it to an empty dict, not setting to None
Harajuko
Hi all, i am trying to use a pony with threading, on the child thread i am trying to use a object fetchend from the parent thread. On child when i try
contract = Contract(address=contract_address, network=self.network)
i get the error: pony.orm.core.TransactionError: An attempt to mix objects belonging to different transactions
this is obviously because i use a object "self.network" from a parent session.
Can i solve?
Thank all
Volbil
Volbil
Also you can't share objects between different db sessions
Harajuko
so i need to "refetch" the object from the child?
Volbil
Yes
Bob
sandi
Hey is there also hybrid setter like in sqlalchemy?
sandi
Or can I use the normal python setter?
Alexander
Hi, you can use normal setter & hybrid getter
sandi
thanks
Ben
For this is the key expected to be a dict? i'm still unsure why the query_results is None
Alexander
It looks like a bug, but the reason for it is unclear. In your code, can you add a few lines in your loan_addons_downpayments function:
python
@property
def load_addons_downlpayment(self):
cache = self.loan_addons._database_._get_cache()
assert cache.query_results is not None
return select(a.downpayment for a in self.loan_addons if a.lead).sum()
Alexander
It is not clear at what moment it becomes None, inside the select call or before it.
Alexander
Or, speaking more precisely:
1) Inside db_session, a cache keeps loaded objects and query results;
2) Before select is executed, the cache flushes unsaved changes to the database;
3) Saving the changes can lead to some exception
4) The exception causes the rollback of the current session. After the rollback, the cache is removed from the db_session, and cache attributes are cleared. This is the moment when query_results is set to None.
5) Next query will request a cache from the db session, and as the previous cache was cleared and removed from the db session, a new cache should be created automatically (with query_results initialized as an empty dict)
So, the error looks like the cache was destroyed after some exception, but the following query still uses the same destroyed cache (which should already be removed from the current db session) and not a new one. I don't understand currently how it can happen.
Probably in your code, you catch some exceptions and may have some non-trivial logic, but it still should not lead to re-using of the destroyed cache.
Harajuko
evgeniy
Hi there.
Please give a link to the bot using ponyorm
Ben
Is there any cleaning done for special characters like Byte Order Mark in Pony? I have text columns containing the BOM that got into my db and no idea how.
Ben
Is there a way with Pony to search those characters with a select?
Ben
Quick question, unrelated, is it expected that timedelta within queries do not have "seconds" attribute? Like this doesnt work:
solvedIssueResolutionTime = orm.select((I.startDate, I.closedDate) for I in Issue if I in solvedIssuesInPeriod)
totalResolutionTime = orm.sum((b-a).seconds for a, b in solvedIssueResolutionTime)
Alexander
Alexander
Ben
it says that 'timedelta' object does not have attribute 'seconds'
Ben
In general Pony does clear non-printable characters like control characters though no?
Ben
or nothing at all is done to sanitize before DB?
Alexander
Since timedelta objects are sumable
Alexander
Ben
thanks a lot for those clarifications!
Ben
Last question: what could cause a db_session to end and not reopen in the middle of a transaction? I have a view that is decorated with db_session but somehow within it I'm getting logs of errors that the db_session is not open
Alexander
Do you suppress any errors by any chance?
Ben
hmmm
Ben
potentially yes, why?
Ben
how could I reopen a db_session after supressing an error?
Ben
I'm also using a flush()
Ben
the error is always raised inside _get_cache()
Ben
@sashaaero Thanks a lot for your pointer, I was catching OrmError in an handler and it seems that it was closing the connection and not reopening it and then causing issues at random points in the code (the next time it needed a db_session)
Alexander
As far as I remeber exceptions trigger '__exit__' for context managers, which closes transaction in case of db_session
Alexander
No problem ;)
Ben
Do you know if there is a way to reopen it? Like after I do a commit() or rollback() it reopens automatically
Alexander
This mechanism is quite complicated
I believe you can use more of "with db_session" usage, so your transactions wont mix with some errors and it would be easier to maintain
Ben
You mean separating my actions in smaller db_sessions so that they are reopened after any place that I do a try/except?
Alexander
Not "reopened" but "opened again", i mean, it is another transaction
Thats just a style i prefer more
It also allows you to do some async things
Ben
ohh, I'm already doing async things with Gevent. Maybe that's why I'm having issues? Could an error in one thread cause an issue in another thread?
Alexander
Yeah, Pony uses ThreadLocal cache, so it can mix object's state between different transactions
So if you do
with db_session:
sync call
if should work fine
Vitaliy
Hello! Does anybody tested Pony with Cockroach? I imported working MySQL dump of existing project to the Coackroach, but it seems there are some bugs in the code.
1) In orm.dbproviders.cockroach:20 there is a try to import PGStrConverter from orm.dbproviders.postgres, but there is no such a class. I fixed it myself by removing this class from the list and adding new import statement:
from pony.orm.dbapiprovider import StrConverter as PGStrConverter
2) But while trying to run the app there is another error thrown:
ValueError: Value of unexpected type received from database: instead of time got <class 'datetime.time'>
It seems that timedeltas are not properly converted. Using some dirty hacks I finally run the app.
Is there more stable (development) version to use Cockroach DB?
Alexander
Hi Vitaliy! It seems the CocroachDB module needs some upgrade; I think I should be able to do it the following weekend. Lately, I have had no possibility to work on Pony regularly; I hope I will be able to find time for it now.
Vitaliy
Here is another problem when accessing uuid attribute:
pony.orm.dbapiprovider.DataError: unsupported comparison operator: <bytes> = <uuid>
Vitaliy
Vitaliy
By the way, it is also will be good to patch MySQL driver to support MariaDB. There are much less problems, probably with JSON syntax only.
Vitaliy
Hello again Alexander! Found another bug related to deletion.
Here is a query:
select(
t for t in Traffic for i in Interval if t.interval == i
if t.timestamp < datetime.now() - i.history
).delete(bulk=True)
It produces following SQL query:
DELETE t-1 FROM `traffic` `t-1`, `interval` `i`
WHERE `t-1`.`interval` = `i`.`id`
AND `t-1`.`timestamp` < SUBDATE(%s, `i`.`history`)
There is syntax error: DELETE t-1 FROM, table name should be quoted: DELETE `t-1` FROM
Vitaliy
It is discovered using MySQL provider, SQLite works fine
Alexander
Thank you for reporting, I'll fix it!
Vitaliy
By the way, above query doesn't works, because it should be SUBTIME instead of SUBDATE.
In orm.dbproviders.mysql:97 there is a function:
def DATE_SUB(builder, expr, delta):
if delta[0] == 'VALUE' and isinstance(delta[1], time):
return 'SUBTIME(', builder(expr), ', ', builder(delta), ')'
In my case delta is not a VALUE but is COLUMN and it has timedelta value.
I think that the expr is need to be checked too.
Vitaliy
I changed if expression to:
if delta[0] == 'VALUE' and isinstance(delta[1], time) or not isinstance(expr, dbapiprovider.DateConverter)
Seems that's enough
Amo
Hi, is there a way to model multiple inheritance in the design tool?
Ben
I'm getting a funny error that seems related to Pony internals:
File \"/usr/local/lib/python3.9/site-packages/pony/orm/sqlbuilding.py\, line 29, in eval "if t is tuple: value = value[i] IndexError: tuple index out of range"
On a fairly straightforward query select(l.id for l in leads)[:]
Ben
If you have any ideas of what might be happening? Sorry to always come up with the most cursed issues
Alexander
Is there a chance that "leads" is n empty tuple, not an entity?
Ben
it's an other select query, that may in some case have an empty result, but it shouldnt be a tuple