Yehor
I got this exception when stopping/starting MySQL to test how Pony will be working
Yehor
Yehor
I am using flask class based views, not just functions
Jones
I create filter of Or's dynamically query.filter(raw_sql(' OR '.join(list_ors))) but expression not resolve when join foreing column "x.technical.name" missing FROM-clause entry for table "technical" LINE 4: AND (reference ILIKE '%M%' OR x.technical.name ILIKE '%M%'... How I put join in clause to resolve expression or any another method. Tks
Xavier
Anyone knows if ponyorm works with kivy on android?
Matthew
If I have a python list of pony objects, how can I filter by whether a Set contains any of the objects in the list?
Matthew
I’m sure I’ve done this before but I’ve forgotten it 🙂
Matthew
items = Set(Item)
Matthew
x.items (any matches) python_list of Items
Matthew
I tried any, but I don’t think it exists in pony?
Alexander
You can exists(item for item in x.items if item in python_list) Maybe there is something more compact, but I cannot look up right now
Matthew
Sorry, nevermind. I realised I actually only have one Item
Alexander
Hi, sorry for delay with the answer. Let me think a bit about it...
Alexander
For many-to-one relationship you can force adding join by adding some condition (which is not raw sql) which mentions this attribute: q = select(x for x in MyEntity) ... q = q.filter(lambda x: x.technical.id > 0) ... q = q.filter(raw_sql(' OR '.join(list_ors))) The condition x.technical.id > 0 is always true, but it forces adding this join
Matt
Well guys, I changed jobs and won’t work with PonyORM anymore, so I’ll leave the channel before long. Thanks for everyone’s help this year, awesome community!
Alexander
Goodbye Matt, and success to you with your new job!
Anonymous
Happy Independence Day everyone
Alexander
🎉🎉🎉
М
Hello everyone! I have a question: is it possible in PonyORM to create tables after you generated mapping, not in exact same time?
Alexander
Hi! Yes, you can call db.generate_mapping(create_tables=False), and later you can call db.create_tables() and db.drop_all_tables(with_all_data=True)
Alexander
You're correct, create_tables is False by default, so I mean check_tables=False
М
Hello again! Your ORM has an awesome syntax of applying number of filters dynamically to one query object: q = select(...) q = q.filter(...) q = q.filter(...) ... It joins filters with AND. Is there a way to do the same thing, but join them with OR? I've seen there a guy, who used query.filter(raw_sql(' OR '.join(list_ors))) for such thing. Is it the only/best way of doing it?
Alexander
Currently we don't provide a way to join filters by OR, because a naive API for that may be error-prone: if you do something like q = select(x for x in X if x.id == 123) q = q.filter(lambda x: x.status == "foo") q = q.filter_or(lambda x: x.status == "bar") q.delete(bulk=True) You may expect DELETE FROM MyTable x WHERE x.id = 123 AND (x.status == "foo" OR x.status == "bar") but actually you'll got DELETE FROM MyTable x WHERE (x.id = 123 AND x.status == "foo") OR x.status == "bar" And this is a totally different query So we need to invent a good API for dynamic OR which is not as error-prone Maybe it should be something like or_items = pony.orm.OrClause() or_items.add(lambda x: x.status == "foo") or_items.add(lambda x: x.status == "bar") q = select(x for x in X if x.id == 123 and or_items) The the query should have expected condition x.id == 123 AND (x.status == "foo" OR x.status == "bar") Right not it is not implemented yet. To implement dynamic OR now you can use filters defined using string with python code instead of lambda function (it is possible to write q.filter("lambda x: x.a > b") instead of q.filter(lambda x: x.a > b)) So you can do something like or_items = [] or_items.append('x.status == "foo"') or_items.append('x.status == "bar"') or_clause = " or ".join("(%s)" % item for item in or_items) q = select(x for x in X if x.id == 123) q = q.filter("lambda x:" + or_clause) Note that here I used Python code in or conditions, while in Jones query above there were used raw SQL expressions inside raw_sql fragment
М
Currently we don't provide a way to join filters by OR, because a naive API for that may be error-prone: if you do something like q = select(x for x in X if x.id == 123) q = q.filter(lambda x: x.status == "foo") q = q.filter_or(lambda x: x.status == "bar") q.delete(bulk=True) You may expect DELETE FROM MyTable x WHERE x.id = 123 AND (x.status == "foo" OR x.status == "bar") but actually you'll got DELETE FROM MyTable x WHERE (x.id = 123 AND x.status == "foo") OR x.status == "bar" And this is a totally different query So we need to invent a good API for dynamic OR which is not as error-prone Maybe it should be something like or_items = pony.orm.OrClause() or_items.add(lambda x: x.status == "foo") or_items.add(lambda x: x.status == "bar") q = select(x for x in X if x.id == 123 and or_items) The the query should have expected condition x.id == 123 AND (x.status == "foo" OR x.status == "bar") Right not it is not implemented yet. To implement dynamic OR now you can use filters defined using string with python code instead of lambda function (it is possible to write q.filter("lambda x: x.a > b") instead of q.filter(lambda x: x.a > b)) So you can do something like or_items = [] or_items.append('x.status == "foo"') or_items.append('x.status == "bar"') or_clause = " or ".join("(%s)" % item for item in or_items) q = select(x for x in X if x.id == 123) q = q.filter("lambda x:" + or_clause) Note that here I used Python code in or conditions, while in Jones query above there were used raw SQL expressions inside raw_sql fragment
I see. Ok, thanks, that was very helpful!
Matthew
What’s the best way to copy a pony object, that has one to many and many to many relationships? I want to preserve everything except the primary key and another field which is a uuid
Matthew
Maybe using to_dict() ?
Christian
What's the state of migrations? I'm at a point again, where I could really use a feature that helps me easily change schemas.
Alexander
Hi Christian! Migrations are not released yet. I hope we can release it in a month. What database do you use?
Christian
MySQL - I've looked at the migrations branch on github, but it's about 6 months behind the orm branch?
Christian
I've read your comments on why it is difficult to implement - from the outside (and only recently following Pony) it seems like this is a big block that's holding up development?
Alexander
Recently the development was slow, because I had absolutely no time to work on Pony. Alexander Tischenko were working on a new version of migrations, with a good success, and I hope we can show it soon. The good news is that I should return to active developing of PonyORM soon. I have some big plans, but first we need to finish migrations...
Christian
Thanks for the update! I appreciate how active you are in maintaining this! 👍
Lucky
Thanks for the update! I appreciate how active you are in maintaining this! 👍
In the meantime, If you really need a solution right now, I’ve made https://github.com/luckydonald/pony_up which might help you. It is more of a manual approach of writing migrations, but executes them automatically, and thus it is still better then executing SQL queries yourself.
Lucky
I needed bigger changes for a project, and at some point couldn't wait with doing migrations.
Alb
Hi guys. Read the docs and didn't see any non blocking examples (i.e using async/await keywords). The only mention about async I saw is here https://docs.ponyorm.org/transactions.html#using-db-session-with-generator-functions-or-coroutines. Looks like Pony is sychronous ORM, right? Are you going to implement asyncronous functionalities in the future?
Alb
Sorry guys, my bad. Didn't read carefully "The @db_session() decorator can be used with generator functions or coroutines too. The generator function is the function that contains the yield keyword inside it. The coroutine is a function which is defined using the async def or decorated with @asyncio.coroutine."
Alb
Will try coroutine
Alexander
Hi Alb! It turns out db_session doesn't work correctly with async code. Specifically, all coroutines will use the same database connection and hense use the same transaction, which is wrong. We need to add real async support for coroutines. Before this, you can use short synchronous db_session blocks inside async code, each db_session should end before coroutine freezes. Alas, it may be inconvenient, as you cannot use the same object in different db_sessions without make_proxy calls
Alb
thank you for clarification
Alb
@metaprogrammer do you have a roadmap or approx terms for adding async support?
Ghulam
hi, I have SQL Alchemy code that I need to convert to pony software_id = Column(String(36)) software_version = Column(String(48)) @hybrid_property def redirect_uris(self): if self.redirect_uri: return self.redirect_uri.splitlines() return [] @redirect_uris.setter def redirect_uris(self, value): self.redirect_uri = '\n'.join(value) how to do that setter decorator in pony?
Ghulam
Oh, never mind, i've figured it out.. 🙏
Lucky
Are you a bot, or real user?
Иван
Are you a bot, or real user?
All bots have username, isn't it?
Lucky
Nah, you can just program a telegram client like the apps.
Lucky
So user-bot, not bot-bot.
Иван
Oh, i didn't know about it
@
Does Pony support Amazon Redshift?
Alexander
I haven't tried it, but I think it should, because the connection to Redshift goes through psycopg2 which is supported
М
Maybe you should use something like that: https://protectronbot.com/ ?
Alexander
We have some oopsie here. We have only two main admins and the creator's account was deleted. So we cant grant admin permissions.
Kaltenstein
Contact tgram support to have ownership reassigned.
Anonymous
^ Is there no way to delete spam like this from the group?
Anonymous
Hey guys, I have some strange issue: I have a table created as: CREATE TABLE "File" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "description" TEXT NOT NULL, "icon" TEXT NOT NULL, "upload_date" DATE, "owner" INTEGER NOT NULL REFERENCES "Owner" ("id") ON DELETE CASCADE ) to store uploaded files in a webapp. When I try to add a file I get errors:
Anonymous
db.File(name=sf, description='en fil', owner=owner, icon='temp text') # => TypeError: Unknow attribute 'icon' db.File(name=sf, description='en fil', owner=owner) # => pony.orm.core.TransactionIntegrityError: Object File[new:1] cannot be stored in the database. IntegrityError: NOT NULL constraint failed: File.icon
Anonymous
Anyone has any clue what could be wrong? Thanks!
Alexander
Can you show your File entity declaration?
Anonymous
@aerok : Ah, thanks. Your question solved it. Turned out I was using an old database created with an icon = Required(string), but in the current, that one was commented. So the first line about was an error from Pony, but the second one from SQLite. My bad, but perhaps the first error could clarify that the attritue icon is in the database but not in the declaration... or maybe that would be difficult to implement. Anyway, thanks.
Alexander
You're welcome. Best way to let us not to forget about this is to create an issue on Github. If it's okay for you.
dovaogedot
Can somebody please share a link where I can find out how to do migrations with pony?
Alexander
Migrations is not released yet, we are working on it
David
Migrations is not released yet, we are working on it
is there any info about migrations release? what do you recommend to use as migration tool with ponyorm?
Alexander
Official migrations are not released yet, we are working on it.This week I return to active development of PonyORM, so the work will go faster. I really hope we can finish before the end of August
Drop
is there any info about migrations release? what do you recommend to use as migration tool with ponyorm?
i use just migration branch from repo. after little improves fields with json type working well, trouble with migrated tables name is still here but it is not critical(for me)
Alexander
Thanks, much appreciated!