Grigory
thanks!
Vitaliy
Awesome! New release 🙂
Alexander
Yeah
Alexander
https://github.com/ponyorm/pony/releases/tag/0.7.7
Vitaliy
Could you please clarify what exactly does this mean: Fix Flask compatibility: add support of LocalProxy object?
Alexander
Flask-login plugin uses current_user global object https://flask-login.readthedocs.io/en/latest/#flask_login.current_user You can set it to Pony entity instance. The resulted object is not really Pony object, but Flask-login proxy. So, previously when you write something like select(m for m in Messages if m.author == current_user) it didn't work. because Pony didn't understand that current_user is equivalent to a entity object. The same problem was with statements like message.author = current_user this line resulted in TypeError Now Pony automatically dereferences current_user proxy to its underlying entity object in this and similar situations
Vitaliy
This is great! 🙂
Vitaliy
By the way, I can report a small bug. Here is what repr returns in console: >>> Admin[1] Admin[True] But Admin[2] is OK
Alexander
hmm
Alexander
What is PrimaryKey type for Admin?
Vitaliy
There is also the same bug when using show() in the console.
Vitaliy
id = PrimaryKey(int, auto=True)
Vitaliy
I tried to format as a text, but it still looks ugly in telegram
Vitaliy
As you can see: (1) 0.00 instead of 0 (2) True instead of 1.00 (3) 0.00 instead of False
Vitaliy
And it is also something has been broken while show an Entity: >>> show(Admin[1]) instance of Admin Traceback (most recent call last): File "<input>", line 1, in <module> File "/Users/vitalium/Sites/env/py36/lib/python3.6/site-packages/pony/orm/core.py", line 6410, in show QueryResult([ x ], None, x.__class__, None).show() File "/Users/vitalium/Sites/env/py36/lib/python3.6/site-packages/pony/orm/core.py", line 6236, in init translator = query._translator AttributeError: 'list' object has no attribute '_translator'
Vitaliy
Here is another demo of this bug: >>> select((ip.network, ip.host, ip) for ip in IpAddress if ip.host == 1).limit(10).show() SELECT "ip"."network", "ip"."host", "ip"."network", "ip"."host" FROM "ipaddress" "ip" WHERE "ip"."host" = 1 LIMIT 10 ip.network |ip.host|ip -----------+-------+--------------- 10.0.0. |1 |10.0.0.True Hope you can localize it quickly!
Alexander
Ok, thanks!
Vitaliy
Hello Alexander! Have you any luck with fixing mentioned abobe bug? I have also encountered similar error on entity creation: ERROR: column “server” is of type integer but expression is of type boolean LINE 1: ...TO "payment_server" ("payment", "server") VALUES (118, true) true here shoud be the 1. So the roots of the problem are somewhere deeper than in repr (__str__) while executing show() P.S. It seems an error above occures when the object Server[1] is in the cache and not yet inserted in DB
Alexander
Hi Vitaliy! I’m away from computer now, maybe I’ll be able to look at it tomorrow. Do you mean this is a new bug introduced in 0.7.7?
Alexander
Oh, I think I understand the reason
Alexander
I’ll try to fix it soon
Vitaliy
I have noticed this bug already in github version about 1-2 months ago and have rolled back to 0.7.6 in my test environment
Vitaliy
Sounds encouraging 🙂 I have refactored my code to use some concepts introduced in 0.7.7 and have no ability to rollback to 0.7.6 again. I’m on the final stage of my huge project development so I will much appreciate your prompt reaction 👍
Alexander
I wish you had reported it when you found it :)
Alexander
I discovered the root of the problem and will try to fix it today
Vitaliy
Yes I should but did not done, shame on me 😳
Alexander
Hi guys! New bugfix release 0.7.8 is ready. It fixes two serious bugs introduced in 0.7.7 and discovered yesterday
Alexander
https://github.com/ponyorm/pony/releases/tag/v0.7.8
Vitaliy
Great, thank you! Works as expected!
M
Hi, I am having a look to all lightweight ORMs in Python to interact qith SQLite. in my case I need to deal with currency fields which would be DECIMAL in Python . As SQLite does not support fixed point numeric fields, I need to use this: https://stackoverflow.com/questions/6319409/how-to-convert-python-decimal-to-sqlite-numeric Based on your experience, would PonyORM fit in this workaround, would it be possible to deal with DECIMAL numbers in a natural way? thanks in advance for sharing your opinion
Vitaliy
@metaprogrammer, here is another bug that easy to reproduce (probably on PGSL): var = [] select(x for x in Entity if x in var) raises TypeError: Cannot search for Entity in IntArray: x in var However select(x for x in Entity if x in []) works OK.
Vitaliy
Expression like Entity.select().where(lambda x: x in var) also fails (edited)
Vitaliy
Currenly the following workaround can be used Entity.select().where('x in %r' % var) 🙂
Zackwolf
Hello I'm zack,wanna ask a question.Can I custom a primary key on model pony ORM ,cause it always detected as "id" and my primary key is not "id"
Henri
https://docs.ponyorm.com/entities.html#primarykey
Zackwolf
Thank u very much I'll try
Anzor
Hi! Cannot stop wondering on how clean and ingenuous do queries look compared to other ORMs! Cannot find out how to do case-insensitive search aside from query.filter(lambda r: substring.lower() in getattr(r, fieldname).lower()) I mean Postgres' ILIKE
Muhammed
You can see the SQL commands with set_sql_debug() https://docs.ponyorm.com/firststeps.html#using-the-debug-mode
Muhammed
Using the debug mode Using the set_sql_debug() function, you can see the SQL commands that Pony sends to the database. In order to turn the debug mode on, type the following: >>> set_sql_debug(True) If this command is executed before calling the generate_mapping() method, then during the creation of the tables, you will see the SQL code used to generate them.
Muhammed
Sorry, I think I got it wrong 😅 I think you wonder SQL commands
Anzor
@yilmazmuhammed Ya, I have sql_debug enabled and that function just fine. The problem (not actually a problem) is that I cannot force pony to do right translation. Not sure this actually implemented for Postgres-specific sql
Alexander
Hi Anzor, currently Pony does not have direct support of ILIKE, but you can write raw SQL fragment: pattern = 'abc%' query.filter(lambda r: raw_sql('r.fieldname ILIKE $pattern')) Not that r inside a query is a table alias. It is defined in previous query as a for loop variable name or the argument name from the initial lambda. So it may be diifferent from r. You can look it up in SQL text If you need to substitute attribute name dynamically (like you do with getattr), you can do it in the following way: fieldname = 'myfield' pattern = 'abc%' sql = 'r.%s ILIKE $pattern' % fieldname query.filter(lambda r: raw_sql(sql))
Alexander
Hi, I am having a look to all lightweight ORMs in Python to interact qith SQLite. in my case I need to deal with currency fields which would be DECIMAL in Python . As SQLite does not support fixed point numeric fields, I need to use this: https://stackoverflow.com/questions/6319409/how-to-convert-python-decimal-to-sqlite-numeric Based on your experience, would PonyORM fit in this workaround, would it be possible to deal with DECIMAL numbers in a natural way? thanks in advance for sharing your opinion
Hi Emmanuel! When using SQLite Pony stores Decimal values as strings without any precision loss. You can choose how many decimal digits you want to store using precision and scale options: myattr = Required(Decimal, precision=12, scale=2) Scale is the number of digits after the decimal point, and precision is the total number of digits
Anzor
@metaprogrammer ah, raw_sql, sure. Thanks!
M
I have an additional question regarding multithreading. I am using CherryPy which is multithread, my understanding is that I can not use Pony as the default SQlite does not handle multiple threads writing at the same time, any comment or experience about this?
Alexander
PonySQL works fine in multithreaded application which uses SQLite. We are making special efforts to avoid sqlite3.OperationalError: database is locked error
Alexander
With SQLite Pony handles transactions manually to avoid locking problems
Alexander
But performance will be better if you perform all insets/updates near to the end of db_session, and all long SELECT queries at the beginning
Alexander
Without Pony using SQLite in multithreaded applications may be problematic indeed
M
Thanks that is good to know (btw there are many messages and forum posts that highlight issues with Pony and SQLite-due to SQlite issues-)
Alexander
hmm. Can you point them to me?
M
I will do once I am back to my PC . (I have been checking all lightweights ORMs and SQLite)
Alexander
ok
M
http://charlesleifer.com/blog/multi-threaded-sqlite-without-the-operationalerrors/ (see first comment)
M
That comment made me discard PonyORM, I was actually considering no ORM and open/close transactions for write operations to avoid multithread issues (read operations can be shared)
M
Actually I thought I had more references about PonyORM but most of them are related to CherryPy with SQLite
M
If PonyORM solves the multithread issues with SQLite in Python that is a great benefit, as far as I know no other ORM does that and for those who want to avoid a larger database it is a really important point
Alexander
I hard to understand to me what exactly he means, maybe this is the following issue: https://github.com/ponyorm/pony/issues/386 It should be fixed now
Vitaliy
It’s OK thank you!
Alexander
https://github.com/ponyorm/pony/releases/tag/v0.7.9 Now empty arrays and empty lists should be handled correctly
Alexander
I hope 0.7.9 release is stable enough that most people can try it
M
Hi, in Oracle you can assign ID as Raw(16) and set DEFAULT to SYS_GUID, which effectively makes each index unique (SYS_GUID would be the equivalent to UUIDs in Oracle). Can you do such thing in Pony with SQlite? i.e. set up and ID which will be raw and will contain an UUID instead of a sequential integer?
Alexander
import uuid from pony.orm import * db = Database('sqlite', ':memory') class Person(db.Entity): uid = PrimaryKey(uuid.UUID, default=uuid.uuid4) name = Required(str) db.generate_mapping(create_tables=True) with db_session: p1 = Person(name='John') print(p1.uid)
Alexander
(not tested)
M
thanks I will test it
Anonymous
When defining a PrimaryKey, is there a way to order/sort the PK either ascending or descending. In Sqlite you can define a PK with either ASC or DESC option, or with no ordering option which gives an unsorted PK. Thanks.
Alexander
I think there is not unsorted PK in SQLite, when you specify PK without ASC or DESC it is equivalent to ASC. At this moment Pony cannot generate CREATE TABLE command with PRIMARY KEY DESC. #todo But if you perform CREATE TABLE command with PRIMARY KEY DESC manually, Pony will be abe to use this table
Genesis Shards Community
Helpme, error: precio = Required(Decimal) NameError: name 'Decimal' is not defined
Alexander
from decimal import Decimal
Genesis Shards Community
thanks!
Genesis Shards Community
error: pony.orm.core.BindingError: Database object was already bound to PostgreSQL provider
Alexander
you do db = Database('postgres', <connection params>) class SomeEntity(db.Entity): ... db.generate_mapping(...) or db = Database() class SomeEntity(db.Entity): ... db.bind('postgres', <connection params>) db.generate_mapping(...) But not db = Database('postgres', <connection params>) class SomeEntity(db.Entity): ... db.bind('postgres', <connection params>) db.generate_mapping(...)
Alexander
You should specify connection parameters only once
Genesis Shards Community
db = Database() db.bind(provider='postgres', user='postgres', password='admin', host='localhost', database='bindiy') db.generate_mapping(create_tables=True)