Lucky
What happens if I set .json_field = None in python?
Alexander
As it declared with NOT NULL, I think database will not allow it
Lucky
Ooof
Lucky
Well, I'll work around it
Lucky
Still strange behaviour
Alexander
I think you can specify nullable=True just as for strings. The logic is similar to strings, to avoid two different empty values (NULL and empty dict) by default
Lucky
That's not possible on the online editor. But still, probably a better way
Anonymous
Then what i can do as of now is p = Product( ..., menus=[Menu[n] for n in my_menus], ... )
Hi, In addition, in case that i want to remove that product only from one menu, for example: p = Product( ..., menus=[Menu[n] for n in my_menus], ... ) and now i want to edit it and remove it from one menu, is there an easy way to do that instead of deleting and re-creating with menus=[Menu[n] for n in my_menus if n >= 5], for example.?
Anonymous
@metaprogrammer 🙏🙏
Anonymous
no that’s not what i want, I have m2m field names menus, Each menu contains many products and each product can be associated to many menus. I want to remove a menu from the menus list of that product, to un-associate the product with that menu Pseudo: product.get_menus() # food, drinks, deserts .. code to remove DRINKS .. product.get_menus() # food, deserts Do you think products.menus.remove(Menu[1]) Will work? Assuming drinks is menu 1
Alexander
You have some specific menu drinks = Menu[drinks_id] and some specific product p = Product[product_id] And there is many-to-many relationship Product.menus <-> Menu.products In order to disassociate product p from menu m you can do either p.menus.remove(drinks) or drinks.products.remove(p) The end result sholud be the same
Anonymous
Oh, i see. Thanks!
Ben
Hi! Is there any way to diagnose why an @property is not being translated properly?
Ben
I have a relatively simple if/else that fails with 'NoneType' object has no attribute 'src'
Alexander
Maybe you just access some optional attribute with None value, like self.optional_attr.src
Ben
I do but I'm checking if they are None
Ben
I actually want to select the rows for which they are none
Ben
Is that not possible?
Alexander
In order to be usable inside queries, property code should be one-liner @property def my_property(self): return ...
Alexander
And due to current limitations you cannot use if-expressions b if a else c
Ben
hmmm
Ben
ohhh right
Ben
thanks
Alexander
Properties should be relatively simple to be included in SQL
Ben
I replaced the ifs by just a bunch of equivalency and OR
Ben
works like a charm
Alexander
Cool
Anonymous
why can i still access this obj even though i deleted it? does it stay in the database too or just in pony's cache?
Alexander
why can i still access this obj even though i deleted it? does it stay in the database too or just in pony's cache?
a.delete() # the object was marked for deletion on flush flush() # the object was actually deleted from the database, # but still present in Python. In Python object status # was changed from "marked_to_delete" to "deleted" a.delete() # does nothing, as object is already has status "deleted" Alternatively it was possible to throw an error if someone tries to delete object which was already deleted, but some users found it inconvenient. So delete was implemented as idempotent operation
Anonymous
if not a.delete(): return “product is already deleted” return “product deleted successfully”
Santosh
@metaprogrammer how do I use between for bigint With SQL something like this is working start_time between 0 and 5000 But with pony orm.between(start_date, 0, 5000) not returning any data
Alexander
@metaprogrammer how do I use between for bigint With SQL something like this is working start_time between 0 and 5000 But with pony orm.between(start_date, 0, 5000) not returning any data
select(x for x in MyEntity if between(x.some_attr, 100, 200)) between(a, x, y) returns logical value which is equivalent to x <= a <= y
Maik
@metaprogrammer i got an NotImplementedError on this line: act = Active.select(lambda a: a.last_active_gr > datetime.datetime.now() - datetime.timedelta(seconds=a.group.active_time) and a.group.groupid == str(message.chat.id)) is there a way to get the active time from the db? the active model has a parrent key to goup where the active time is in
El Mojo
hello pony guys 🙂 let's say I have this entity : service -> customers -> locations I want to fetch a "service" object and within that service I need the locations to be ordered by attribute "X". is this possible in a simple way ?
Alexander
@metaprogrammer i got an NotImplementedError on this line: act = Active.select(lambda a: a.last_active_gr > datetime.datetime.now() - datetime.timedelta(seconds=a.group.active_time) and a.group.groupid == str(message.chat.id)) is there a way to get the active time from the db? the active model has a parrent key to goup where the active time is in
Try to use raw SQL fragment: dt = datetime.datetime.now() act = Active.select(lambda a: a.last_active_gr > raw_sql('''TIMESTAMPADD(SECONDS,-"group".active_time, $dt)''') and a.group.groupid == str(message.chat.id))
Maik
thanks @metaprogrammer but where stands the dt for? its empty
Alexander
Ops, fixed it
Maik
@metaprogrammer pony.orm.dbapiprovider.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'SECONDS,-"group".active_time, \'2021-04-09 13:02:01.944962\')\n AND group.`group\' at line 3')
Alexander
multiple services actually 🙂
You can do service_query = Service.select(lambda s: some_condition) for service in service_query: locations_query = service.locations.select().order_by(lambda loc: loc.name) for loc in locations_query: ...
Alexander
If you want to do it in a single query: select( (srv, loc) for srv in Service for loc in srv.locations ).order_by(lambda srv, loc: (srv.name, loc.name))
Alexander
@metaprogrammer pony.orm.dbapiprovider.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'SECONDS,-"group".active_time, \'2021-04-09 13:02:01.944962\')\n AND group.`group\' at line 3')
Try SECOND instead of SECONDS You can activate sql_debug(True) and check query syntax. You can try to execute query manually in MySQL console to check syntax (doing this, you need to substitute parameters directly into the query).
Maik
@metaprogrammer INFO:pony.orm:GET NEW CONNECTION INFO:pony.orm.sql:SELECT a.id, a.group, a.user, a.last_active_gr, a.super_admin FROM active a WHERE a.last_active_gr > TIMESTAMPADD(SECONDS,-"group".active_time, %s) INFO:pony.orm:ROLLBACK INFO:pony.orm:RELEASE CONNECTION to run it in mysql query i didnt manage too
Maik
i saw i have in navicat an query builder i manage there to build the line and run it with select_by_sql thanks for the help @metaprogrammer
Anonymous
Team.... how do you force ponyorm to use pymysql versus the other api?
Alexander
Hi! What is the reason to force it?
Anonymous
I am on an m1 mac and the c connector won't install from brew
Anonymous
so the docs say it can use either, but it does not say how, it just says use mysql on the bind
Alexander
I think if you have pymysql and no other drivers pony should use pymysql
Anonymous
well I tried uninstalling the other drivers and it still won't use pymysql
Alexander
Pony tries to import MySQLdb and fallback to pymysql on ImportError
Anonymous
I tried to clear my system
Anonymous
what if my mysqldb install failed and ponyorm still thinks it is on my system
Alexander
Currently Pony tries to use pymysql only if importing MySQLdb leads to ImportError. Maybe we can change it in the future
Anonymous
I just tried to uninstall pymysqldb and ponyorm still does not fall back to pymysql
Anonymous
pymysql installed correctly
Anonymous
pymysqldb reported it was not installed
Alexander
You can add local modue named MySQLdb with a single line raise ImportError
Anonymous
??????
Alexander
I mean, as a quick workaround
Anonymous
Thanks so much again fro the support sir, really nice of you
Alexander
Sure
Anonymous
I am not sure I get what line of code to add to raise the importerror
Anonymous
I am not sure I get what line of code to add to raise the importerror
yourProject: YourFile.py MySQLdb.py: raise ImportError
Anonymous
ah, let me try that workaround
Anonymous
thank you much sir, I was able to connect ponyorm to pymysql
Anonymous
I will carry on with ponyorm on my mq
Queso Di Pesto
Hello!! The online editor is off?
Alexander
Thank you for reporting, it should work now