Lucky
Maybe pony is missing there
stsouko
Read about hooks
stsouko
https://pythonhosted.org/PyInstaller/hooks.html
Anonymous
Thanks for the advice! I'll look into that
az
hello
az
if I need to use ponyorm entities from several python modules, I need to import these entities in every module, do I understand this correctly?
Lucky
Yeah
az
and do I need to use db.bind inside each of these modules?
Henri
bind and mapping you use only once.
az
can I generate mappings inside a function?
az
I have a code similar to:
from . import models
def init_db(db):
db.generate_mapping(create_tables=True)
az
and mappings are not generated
az
looks like I'm only able to use the orm if it is defined at the global context, is there a way to somehow pass context between functions?
Lucky
It should be possible
Matthew
Hey, big pony user, just noticed there's a telegram group :)
Alexey
Lucky
Matthew
Are the main authors planning future development on pony's core?
Alexander
Yes, we are. We need to finish migrations first, because it blocks other tasks.
Matthew
Great to hear :)
Matthew
Is the migrations work in progress currently public?
Alexander
No, but I hope to release it soon. The problem with migrations is that we need to change previous tables to make it compatible with migrations. This requires upgrade of previous tables. After such upgrade it is not possible to use previous version of Pony. So we need to be sure that everything is good
Matthew
I'm happy to help test this, I have a few projects with reasonably complex pony-created tables.
Matthew
Not on my live database of course
Alexander
Good to hear. Give me few days, and I'll release migrations branch to public
Henri
👌
Anonymous
Hey Alexander, I guess you are getting a lot on this, using MySQL enums with Pony.
I have followed this tutorial: https://mailman-mail5.webfaction.com/pipermail/ponyorm-list/2014-September/000125.html
And ended up with this code: https://paste.ofcode.org/Ed2jS3t2pHNeUSdRznuc6R
Getting this error: TypeError: Expression UserGroup.Regular has unsupported type 'UserGroup'
It happens in extract_vars inside core.py and it probably fails within get_normalized_type_of(UserGroup.Regular).
Can you suggest something?
Alexander
Hi @dereli, I ran your example but encounter some other problems as well. I'll try to analyze it and will answer tomorrow
Anonymous
@akozlovsky, the other problems on my code or some other unexpected issues with Pony? Thanks btw.
Lucky
Lucky
I thought it would still be in planing phase.
Lucky
That's why I later crated github.com/luckydonald/pony_up
Alexander
Wow, that's interesting, we will look into it
Anonymous
They were never invoked for me, so I couldn't make sure they're correct. If I can be of any help on that please advise.
Lucky
Matthew
Matthew
if there is the explicity casting to a list with [😏 wont that stop an SQL LIMIT being included?
Matthew
[ : ]
Lucky
Matthew
:)
Lucky
Lucky
Matthew
ah yes, good point, like [ :1 ][ 0 ]
Alexander
Also a lot of functions are not documented.
There are two type of API - an external API for users who just define entities and an internal API for developers who want to write some extensions. At this moment we document the external API but not internal one. At some moment of time we need to document internal one as well, but after that it will be harder to change it.
Matthew
Would it be possible to have timing of SQL queries when debug mode is turned on? I often find myself timing a bunch of queries when debugging performance issues. For example sql_debug(timing=True)
Matthew
then after the SQL is printed, also showing the time in milliseconds to execute
Alexander
Pony already gather such statistics, but don't output it to the log, because the SQL query is printed before execution, not after it (otherwise it would be hard to understand which query caused database exception).
You can do the following:
db.merge_local_stats()
stat = db.global_stats
for sql, query_stat in stat.items():
print(sql)
print(query_stat.max_time, query_stat.avg_time,
query_stat.sum_time, query_stat.db_count, query_stat.cache_count)
Matthew
Thank you, if that is not in the documentation ,it would be good to add
Alexander
http://ponyorm.readthedocs.io/en/latest/api_reference.html#QueryStat
Alexander
It is in API reference, maybe we need to add it to other parts of documentation as well
Rus
What about pony orm and graphql?
Alexander
Vitalii Abetkin wrote the initial version of Pony GraphQL API, you can find it here: https://github.com/abetkin/pony_graphql
You can ask Виталик for details of how it works
Anonymous
Hey @akozlovsky, I guess you couldn't have time for the Enum problem, maybe you can lead me, and I can dive in and try to work on it during the weekend..
Alexander
Hi, actually I was able to make code work about half a hour ago.
In order to do this it was necessary to change some code inside Pony. We don't develop Pony in a way when new types can be added completely externally without changing Pony code itself, because in order to be completely extensible the code needs to be more complex.
I can push my changes to separate branch in our GitHub repository. I don't want to merge them to the main branch ('orm'), because in order to do this we need to add support of other databases as well.
Also, be aware that there are some drawbacks in using enums in the database:
http://komlenic.com/244/8-reasons-why-mysqls-enum-data-type-is-evil/
Anonymous
thanks a lot, I can use that code for sure.. I will ready the article..
Actually I need this because the DB is already using Enums and the codebase is JS/NodeJS. So I want to make it a bit more compatible.
Alexander
https://github.com/ponyorm/pony/commit/b278886d32a330d48307efe817aa4dfd8f6cbe21
Alexander
The code is a bit experimental, some corner cases may not work as expected
Lucky
Will this - in the long run - allow list type on postgres as well?
Alexander
yes
Lucky
This is great 👍
Matthew
Can someone please explain what the root cause of this kind of error is?
UnrepeatableReadError: Phantom object SpyResult[718929855] appeared in collection SpyProduct[2777314].results
Matthew
It comes in a select query that has been cast to a list, nothing exotic
Matthew
I get it on a very small percentage of requests, but I can't seem to stop it happening completely
Matthew
I think it's a normal @db_session
Matthew
results = select(sr for sr in SpyResult if sr.product == self and
sr.date >= datetime.date.today() - datetime.timedelta(days=num_days)).order_by(SpyResult.id)[ : ]
Matthew
that's the query
Alexander
You have one-to-many relationship between SpyProduct and SpyResult: SpyProduct.results <-> SpyResult.product.
At some moment Pony loads all items of SpyProduct.results collection for specific product. In that case, Pony mark the collection as fully loaded in order to not issue additional queries to database. But then you retrieve another SpyResult object which turns out to be related with the same SpyProduct. It is possible if that SpyResult object was created a moment ago in some concurrent transaction. In that case Pony decided that another transaction modified collection which was considered fully loaded, and it is unsafe to continue working with inconsistent data
Matthew
Ok, thank you. Is there a way to ignore new objects that have been created in another transaction? Isn't the idea of a transaction to have an isolated view of the system, regardless of what happens in other transactions?
Alexander
Yes, but PostgreSQL by default does not provide full isolation between transactions. It works on READ COMMITTED isolation level, where you can immediately see results of completed concurrent transactions.
You can try to use db_session with serializable=True option, in that case it will provide full isolation at some performance expence. When PostgreSQL works with fully isolated transactions it may throw exception if the achievement of full isolation is not possible
Matthew
"At some moment Pony loads all items of SpyProduct.results collection for specific product. In that case, Pony mark the collection as fully loaded in order to not issue additional queries to database. "
- I turned debug mode on with pony, and I don't see any query that selects all SpyResults, only the specific query I pasted above?
Alexander
Maybe you do iteration over product.results collection. In that case Pony loads all items into memory
Matthew
would doing len(product.results) trigger that?
Matthew
I think it does, as it's not doing COUNT(*)