Edis
Right?
Alexander
if you remove '+00:00' if will be parsed by Pony as timezone-naive datetime value
Alexander
Pony expects all datetime values are timezone-naive in UTC
Edis
Hmm
Edis
I'll try that
Edis
works
Edis
thank you
Alexander
Sure
Edis
Hey, I got another question. Does async work with sqlite?
Alexander
Hi! Async support in Pony is not working properly.
Are your application async?
Edis
Yes
Evgeniy
Yes
It seems that Pony has something for working with the database right from the front.
Edis
It's basically async functions that get executed when an event occurs
Edis
I wonder if it blocks the thread if I use it just like that
Edis
Evgeniy
I saw something like that, but I remember it vaguely.
Alexander
Alexander
I wonder if it blocks the thread if I use it just like that
You can use db_session inside async functions. But such functions should not do async calls and context switches inside db_session.
If you want to do some complex processing which can take a lot of time it is better to do it in a separate thread
Edis
I'm not very experienced, just to make sure I understood. So if I use await in the same function, it is a problem?
Alexander
You can use await in the same function, but not inside db_session
Edis
I see
Edis
Thank you
Evgeniy
Edis
You mean with with?
Alexander
Yes
Edis
Instead of the annotation
Edis
Yeah, I'll do that
Edis
Thanks guys
Anon
It's should be possible to offload the db call into another thread through
Anon
and make it async that way
Anon
loop = asyncio.get_running_loop()
with concurrent.futures.ThreadPoolExecutor() as pool:
result = await loop.run_in_executor(pool, functools.partial(yoursyncfunction, args))
Edis
Thank you I'll try that
Edis
Good that you actually included some code snippet xD
Anonymous
is there any simple way to explode a list as parameter(to using in a "in") when using Database.select?
Alexander
If you do
mylist = [1, 2, 3]
query = select(x for x in X if x.id in mylist)
it should work
Anonymous
sorry, i refering using raw queries ... db.select("select * from table where field in ($list)")
Anonymous
thx
Anon
I'm working on adding support for SQL Server, any suggestion which of the tests I should test it with? I've looked through a few but most of them seem related to pony itself rather than testing the dbproviders
Anonymous
Any recomendation to convert a <class 'pony.orm.core.row'> into a Dict ?
Matthew
pony.orm.core.DBSchemaError: Foreign key fk_facebookcommentmoderationaction_facebookcommentmoderationrul cannot be created, name is already in use
I think I hit this before, could it be a length issue? that’s 63 chars long
Matthew
How can I set a custom index name? I can’t see how in the docs
Matthew
Thank you 🙂
Alexander
https://docs.ponyorm.org/api_reference.html?highlight=fk_name#cmdoption-arg-fk_name
Matthew
fk_name worked
Matthew
Maybe the error message could be better?
Alexander
This error is generated by database.
Pony need to deal with very long names that exceeds max name length limit by cutting it and adding some hash value to the end, it will be added with migrations
Matthew
sounds good!
Alexander
Any recomendation to convert a <class 'pony.orm.core.row'> into a Dict ?
At this moment there is no universal way to do this.
Note that you can access row columns by name, if the column name is valid Python identifier:
rows = db.select("* from student")
for row in rows:
print(row[0], row[1])
print(row.name, row.gpa)
To convert row to dict you need to know query result's column names:
names = ['name', 'gpa']
d = {name: row[i] for i, name in enumerate(names)}
Maybe we should add some generic method for converting a row to a dict
alex
Are there any plans to add async support to pony? (With the @db_session decorator)
Alexander
Not in the near time, as async is not easily compatible with IdentityMap pattern used by Pony
alex
I see. Thanks!
Jim
Hi:
class AAA(Entity):
bbbs = Set("B")
class BBB(Entity):
aaa = REquired(A)is it possible to retrieve "bbbs" (I mean the name of the attribute") but from the BBB class ?
Alexander
Yes:
BBB.aaa.reverse.name
Jim
thanks, is it possible to put some attibute (Required, Optional) inside a Mixin ? I get an assertion error :
def load(attr, obj):
cache = obj._session_cache_
if cache is None or not cache.is_alive: throw_db_session_is_over('load attribute', obj, attr)
if not attr.columns:
reverse = attr.reverse
> assert reverse is not None and reverse.columns
E AssertionError
Alexander
Mixins are not supported yet
Jim
ok
Kyle
Hi
Kyle
Just got this error after migrating my mariadb to pg
Kyle
TypeError: Attribute table.col: PostgreSQL provider does not support unsigned bigint type
Kyle
=\
Kyle
col = Required(int, size=64, unsigned=True, default=0)
Kyle
I need to speficify the size or everything won't run since pony will limit between int min and max
Alexander
PostgreSQL is indeed does not support unsigned integers. When you use unsigned=True in attribute description Pony uses bigger size to be able to keep all values (say, integer instead of unsigned smallint). But there is no bigger size for bigint
https://stackoverflow.com/questions/20810134/why-unsigned-integer-is-not-available-in-postgresql
Kyle
Oh its pg thing, sorry for my lack of knowledge and its about unsigned, not size as I though at first
Kyle
Thanks @metaprogrammer
Alexander
Sure
Виктор
Hey! An online diagram editing tool has the checkbox "Hidden" in entity settings, but I found nothing about it in docs
Виктор
What does it do?
Alexander
It was for PonyJS library which was not officially released, we need to remove it
Виктор
thanks for the answer and your cool library ❤️
Jim
hi,
return select(
matiere
for groupe in self.groupes.order_by(lambda g: g.position)
for matiere in groupe.matieres.order_by(lambda m: m.position)
)
position` is a property for a _position attribute.
I get the following error : AttributeError: groupe.matieres.select().sort_by
Jim
return select(
matiere
for groupe in self.groupes.order_by(GroupeMatiere.position)
for matiere in groupe.matieres.order_by(Matiere.position)
)
return the error TypeError: order_by() method receive an argument of invalid type: <property object at 0x7fbba8a9c400>
Jim
and finally :
return select(
matiere
for groupe in self.groupes.order_by(GroupeMatiere._position)
for matiere in groupe.matieres.order_by(Matiere._position)
)
TypeError: Expression Matiere._position has unsupported type 'Required'
Jim
Any idea on it ?
Lucky
Any idea on it ?
Can you please send the model definition as well, please?
Alexander
You need to apply ordering to the outer query, something like that:
select(
matiere
for groupe in self.groupes
for matiere in groupe.matieres
).order_by(
lambda matiere: (matiere.groupe.position, matiere.position)
)
Jim
yeah that was simply that, tahnks