El
I found out. It is because I am creating a PrimaryKey with id and kind.
licet
Who from Canada?
Mario
Hey guys! Does anyone know what could be causing the following error: pony.orm.core.TransactionError: Unexpected class change from <class 'core_system.operational_entities.models.Village'> to <class 'core_system.operational_entities.models.Cluster'> for object with primary key 1
Mario
The code is just reading a record from a third model person with a foreign key to Village. Village and Cluster are both inherited models from another base model for locations
Mario
the foreign key is to Village not to the Location model
Alexander
Hi Mario!
You have two subclasses Village and Cluster inherited from the same base class. Some Person instance refers to the object with primary key value 1. According to the database schema, it should be Village instance. When your code loads this Person instance, Pony sees a foreign key to value 1, thinks "hmm, there should be Village instance with this ID", and creates in-memory representation of this instance in advance.
But then, when Pony actually tries to load this referred object with the primary key value 1, it surprisingly sees that the object with this ID value is not Village, but Cluster. Cluster is not a subclass of the Village, so Pony throws an error, because the database content is not correspond to the database structure.
You need to check row with primary key 1 in the database admin interface and check the vale of its "classtype" column (it should be "Village", not "Cluster")
Mario
Hey Alexander, thanks for the help. The database is in memory and is run in some automated tests so its difficult to access it externally, but if just before the exception I make a direct query I see to thing: there is no such column "classtype" and the discriminator value that I am using correspond to Cluster as it should be. In the schema (the code actually since the db schema is generated by pony) the property person.village is a fk to Village, and village.parent a FK to Location (not specified which subclass). So i dont understand how reading the property person.village.parent raise that kind of error since in the schema is not specifed if it should be vilalge or cluster
Mario
might be that pony assumes that if an entity Village inherited from Location, has a fk to Location, that location must be Village too?
Santosh
Can we use raw SQL in filter or where method?
Currently using in select as below
users = (u for u in User if raw_sql(". "))
Santosh
Can anyone let me know if this is possible
Alexander
Yes, it is possible. Something like
q = select(u for u in User)
x = 10
q = q.filter(lambda: raw_sql("u.column1 > $x"))
Santosh
Santosh
q.where(lambda: raw_sql(""))
Is this correct?
Alexander
$x converted to proper SQL parameter
Alexander
But if you actually need to use $ inside SQL expression, write it as $$ instead
Alexander
Alexander
Mario
Ok in the end the problem was that for one person the FK to village was being set as village=1 instead of village=python_object_representing_the_village. And pony was not checking if that id correspond to the appropriate class or not, just when reading but not when creating
Dmitriy
Hi, is Pony ORM still developed?
last release was half a year ago, and it still hasn’t reached 1.0
Alexander
It is still developing, but the development speed is slowed down last years. The next release hopefully will be released in a few days.
We don't have a plan to reach version 1.0 soon, many projects were developed with version number below 1.0 for many years
Dmitriy
Alexander
Migrations were developed around 2-3 years ago, but it still has several problems we didnt solve due to low time resources.
Dmitriy
that’s a pity 🙁
thanks for the info
Dominik
Maybe a crowdfunding would help secure the resources required to push te final changes? That's how Django got it migrations tool integrated.
Andrea
Hi, I need some help with an issue I'm having.
The following query works just fine:
select(
u for u in User
if
u.public or
other is not None and (
u.privacy == User.Privacy.PROTECTED or
u.is_fellow(other)
)
)
However, when I try to separate the logic in a function and other is None, I get the following error:
class CmpMonad(BoolMonad):
EQ = 'EQ'
NE = 'NE'
def __init__(monad, op, left, right):
if op == '<>': op = '!='
if left.type is NoneType:
assert right.type is not NoneType # AssertionError: other is not None (inside can_read_user)
where can_read_user is just a function that implements the same logic:
def can_read_user(user: User, other: User=None) -> bool:
return (
user.public or
other is not None and (
user.privacy == User.Privacy.PROTECTED or
users_are_fellows(user, other)
)
)
And the query becomes:
select(u for u in User if can_read_user(u, other))
I want to separate the logic because I need to reuse it in other parts of the code. What's the purpose of that assert, and why it works when it's not encapsulated in the function?
Thanks
SlowJoCrow
forgive me for my ignorance, but im trying to learn python on an embedded device. It has a libs folder... is it possible to 'compile' Pony into a file to include on the device libs folder?
SlowJoCrow
the instructions say use "pip install pony" to install, but I want to get a file to put in libs folder
Matthew
you could download pony from github and copy that directory into the correct place on your device
Jan
Hello, I am planning to use PonyORM commercially. The scale is not large. I wanted to check if a license is required for commercial use. The website https://ponyorm.org/buy/large-enterprise is targeted towards large enterprises, which we definitely are not. However, the link “License and Pricing” (https://ponyorm.org/license-and-pricing.html) is broken. I can not find an official contact handle. At the same time, the GitHub Page lists the project under the Apache 2.0 license, which would make it free to use commercially. I am kind of confused. Is there any other information page regarding this available?
Thank you.
Volbil
Permalink Bot
Volbil
Jan
Jan
Volbil
@metaprogrammer could you clarify this?
Alexander
Jan
Rozen
Rozen
Hi!
pony has support for bulk creation?
Huỳnh
Rozen
so, what's your analysis ?
Alexander
Hi!
pony has support for bulk creation?
Hi! Pony has db.insert(**columns) method, which directly performs INSERT without creating the object in memory.
It does not combine multiple rows into a single INSERT statement, but still much faster than creation of full-blown ORM objects
Ben
Hi! I'm getting a strange KeyError issue that seems to be in Pony code in core.py line 5203. @metaprogrammer Do you mind if I send you the traceback so you can confirm if from Pony?
Alexander
Hi Ben! Thank you for reporting! Sure, send me a traceback. I can look at it a bit later today
Rozen
Hey, is there any way to create separate tables for models with shared inherited columns?
Rozen
here https://docs.ponyorm.org/entities.html#representing-inheritance-in-the-database
say's it does not support it but maaay beee
Alexander
Hi! No, it is not supported. Maybe you can emulate it manually, something like
class Person(db.Entity):
name = Required(str)
class Student(Student):
student_info = Optional("StudentInfo")
class Professor(Professor):
professor_info = Optional("ProfessorInfo")
class StudentInfo(db.Entity):
credits = Required(int)
student = Required(Student)
class ProfessorInfo(db.Entity):
degree = Required(str)
professor = Required(Professor)
student_info and professor_info are declared as Optional in order to have foreign key columns on the other side, in StudentInfo/ProfessorInfo tables
Rozen
Genesis Shards Community
hi, it is problem! wait?
Genesis Shards Community
Genesis Shards Community
Hello everyone, I have this error, in mysql it runs fine, but when I switch to postgres I got this error
zuoike
Genesis Shards Community
Alexander
Hi, you can turn on the output of SQL commands using sql_debug(True) before calling db.generate_mapping() and check the SQL code of the last command
Genesis Shards Community
ok, thanks!
Victor
Hello everyone. Did anyone tried to run Pony with Columnstore, MariaDb engine?
Victor
Since I have to remove the indexes, and also the keys associated with the tables, I have many integrity errors when I try to run the system migrated from InnoDb engine. Does anyone tried something similar? Any idea about how fix the integrity problems without the explicity key restrictions in tables creation?
Elier
Hello everyone, does Pony support Embedded Values? https://martinfowler.com/eaaCatalog/embeddedValue.html
Alexander
Hi! Currently Pony does not support Embedded Values. For some use-cases you can use JSON attributes with a complex structure
Victor
Hi Alexander. Can you share some reference to use Pony with multithreading (or multiprocesses)? For example, how to avoid TransactionErrors? How to deal with nested db sessions?
Victor
Thanks Alexander. Since a db session would be already created and active, a commit (+ rollback?) just before dispach and start the new threads running a function decorated with db session would be enough? Does it make sense?
Alexander
Maybe I don't fully understand what do you mean
# this is incorrect
with db_session:
start new thread
# this is correct
def run_in_new_thread()
...
process_transaction()
@db_session
def process_transaction():
...
Alexander
The first is actually correct as well, but inside new thread you need to start its own db_session
Alexander
So each thread which want to work with the database should create its own short-lived db_session for each transaction
Victor
The actual code is structured in a way that ressambles the first situation, but the chalenge is to adapt so the threads are created before get in the db context, as you suggested.
Alexander
It is unclear, why do you need threads at all
Alexander
Is it a GUI application, web server, a bunch of analytical scripts?
Victor
I'm generating data to ML tasks and the model is producing very large tables (GB). I'm trying to paralelize some tasks to reduce the processing time.
Alexander
So you already have single-threaded single-processed version, and want to split the load over multiple CPUs
Victor
Exactly.
Alexander
Then probably its single-threaded version looks something like:
@db_session
def main():
for data in something:
process_batch(data)
def process_batch(data):
# do the work
And at first you need to change it to
def main():
for data in something:
process_batch(data)
@db_session
def process_batch(data):
# do the work
And then you can use multiple threads or processes, where each process will run process_batch(data) in a separate db_session in parallel
Victor
It is something like that but with many classes, methods and data dependences. :)
Anonymous
Hello. I hate to be that person, but is this project under active development? I like what I'm seeing so far, but I'd want to have a migration system in place if I were to use the library. My understanding is that it's in development for the next release.
Alexander
It's okay.
As I mentioned before - development is not in active mode due to lack of resources.
Someone proposed to make crowdfunding project - we need to think about it.
Alexander
Also - we have migration tool almost ready, since it's open source probably someone could fix and it would be ready to use.
Anonymous
Yeah, I scrolled up and saw that. I assume the "resources" needed is just the pure time the developers need to put in to finish the release?