@ponyorm

Страница 71 из 75
Krzysztof
22.09.2018
19:44:34
One more question: why isn't it possible to set nullable for a bool type in Diagram Editor? Is it a limitation of one of the database backends, or just a mistake?

Alexander
22.09.2018
19:46:39
For all types except strings, "Optional" means "nullable"

Krzysztof
22.09.2018
19:47:15
Oh, alright. My bad. ?

Alexander
22.09.2018
19:47:23
No problem

Google
Krzysztof
22.09.2018
19:48:35
But as you are already here, can I ask, when the 0.8 version (with migration support) will be released and stable? Do you have any idea?

Alexander
22.09.2018
19:49:59
Unfortunately it's hard to say at this moment. We need to do some major refactoring before, it's hard to esimate how long it will take

Krzysztof
22.09.2018
19:52:28
Alright, then how safe is it to use orm-migrations at the moment? And will the transition from this branch to 0.8 be smooth?

Alexander
22.09.2018
19:59:23
I think orm-migrations branch should work pretty good for simple cases. The database structure for final migrations release should be the same as in orm-migrations branch. It is possible that the syntax of migration files will change. It this case it should be possible to delete previous migration files, make a new initial migration file with a new syntax and continue using the same database

Krzysztof
22.09.2018
20:00:46
Okay, thank you very much! Sorry for bothering you with such trivia.

Alexander
22.09.2018
20:00:57
I think, there may be problems with SQLite, so you can try orm-migrations if you use PostgreSQL or MySQL

Krzysztof
22.09.2018
20:01:36
Good to know, because I'm planning to use SQLite for now. I'll try to avoid migrations for now then, thanks!

Alexander
22.09.2018
20:02:05
Okay, thank you very much! Sorry for bothering you with such trivia.
No problem, mgration status is a typical question for PonyORM, for which I don't have definitive answer yet

Krzysztof
22.09.2018
20:02:45
But when you'll overcome that, the Pony will became a truly rock-solid option. :-)

*become

Alexander
22.09.2018
20:03:01
Yeah, I think so :)

Krzysztof
23.09.2018
16:21:09
Sorry to bother you once again, but I believe there is a bug in diagram editor. When an entity A has a Set attribute of entities B, and entity B has entity A as part of its PrimaryKey, entity A has default behaviour of cascade delete set to False. I believe it should be True, because part of PrimaryKey is actually more or less Required as well. You can check it here: https://editor.ponyorm.com/user/freewolny/bug

Besides that, sometimes I encounter a situation when the whole diagram disappears and my tab is just empty, white. Then I have no choice but to refresh it, which causes loss of unsaved changes. I learned the hard way to save it regularly.

Google
Krzysztof
23.09.2018
16:25:51
I know that's just a helper web app and it's not something you're focused on, but I thought you should know what to fix when you'll have some spare time for it.

There is also a problem with Pony ORM itself, specifically with returning primary keys of an object. Do you have a minute?

Alexander
23.09.2018
19:21:30
Hi, I'm away from computer now, but you can describe it

Krzysztof
23.09.2018
19:24:00
Alright. Let's consider a following scheme: class A(db.Entity): b = Required('B') c = Required('C') xs = Set('X') PrimaryKey(b, c) class B(db.Entity): id = PrimaryKey(int, auto=True) asses = Set(A) class C(db.Entity): id = PrimaryKey(int, auto=True) asses = Set(A) class X(db.Entity): a = PrimaryKey(A) something = Optional(str)

Let's create some objects: b1 = B() c1 = C() a1 = (b=b1, c=c1)

Let's see what a1 is: >>> a1 A[B[1],C[1]]And what's its primary key: >>> pk_a1 = a1.get_pk() >>> pk_a1 (1, 1)That is indeed correct, and the following works as expected: >>> A[pk_a1] A[B[1],C[1]]

Now let's create a fourth object, of class X this time: x1 = X(a=a1)What is x1? >>> x1 X[A[B[1],C[1]]]Yeah, that is correct. Let's now get its primary key: >>> pk_x1 = x1.get_pk() >>> pk_x1 (1, 1)

It's not correct. Since the primary key of object X is an A object, the primary key of x1 should be a1, or rather primary keys of a1. So the expected value would be ((1, 1),).

Indeed, the following fails: >>> X[pk_x1] TypeError: Invalid count of attrs in X primary key (2 instead of 1)

And returning the primary key as a one-element tuple, as mentioned above, would work: >>> pk_x1_correct = ((1, 1),) >>> X[pk_x1_correct] X[A[B[1],C[1]]]

I know that instead of this we could just use repr(x1) and go from there, but returning primary key should work anyway.

I'm sorry for my elaborated narration.

It just feels easier to explain this way. :-)

Alexander
23.09.2018
19:44:21
Thank you for detailed reporting, I'll check it and write an answer

Denys
24.09.2018
12:46:00
Hey there ? I’m using this ORM in my code and want to mention - I really like it ? Still I have a question - I’have a many-2-many relation. Is there simple way to delete all from intermediate table ? class User(db.Entity): name = orm.Required(str) tags = orm.Optional('Tag') class Tag(db.Entity): name = orm.Required(str) users = orm.Optional(User) I want to remove all data from user_tag table I know that I can create a UserTag model explicilty. and then to use UserTag.delete() But want to know - is there a way to avoid this. And to do smth like User.tags_model.delete() ? Or to write raw SQL for this ? "DELETE from user_tag" Tnanks!

Alexander
24.09.2018
12:48:32
Hi, if you want to delete all rows from many-to-many table you need to use raw sql, like the following: db.execute("delete from %s" % User.tags.table)

Denys
24.09.2018
12:53:37
Yes! That’s what I was looking for! ? A little proposition = may be we need to mention this in https://docs.ponyorm.com/queries.html#using-raw-sqlpage ?

Thanks!

Alexander
24.09.2018
12:55:49
Sure. Actually, the code I posted will not work if the table name is a tuple (that is, includes a schema name). Probably we need to add a method for receiving properly quoted table name with all components

Rozen
27.09.2018
21:30:21
Hi

Google
Rozen
27.09.2018
21:31:04
There is a way to "config" the classt to have it's own table even if it has another parent class?

Alexander
27.09.2018
21:36:04
Hi. In Pony all subclasses share the same table. There are three ways to implement inheritance in the relational database. http://www.vertabelo.com/blog/technical-articles/inheritance-in-a-relational-database Pony uses single-table inheritance, because it is faster (as it does not require a join on data retrieving). In the future is is possible to add another types of inheritance to PonyORM, but it is a big amount of work, so I don;t think we will add it soon

Rozen
27.09.2018
21:42:22
In wich way is it faster? i thought large databases had the problem of it's length

maybe i am doing something wrong

i have some behaviour that some classes share

but the only thing they share is that behaviour

Matthew
27.09.2018
21:43:07
python code behaviour on the classes?

Alexander
27.09.2018
21:44:48
If classes share only small part of attributes/behavior, (like, updated_at attribute), maybe they should not inherit from the same base class

Rozen
27.09.2018
21:45:23
mmmm

Matthew
27.09.2018
21:45:32
yes, just call out to a common function etc

Rozen
27.09.2018
21:47:39
maybe can i have multiple inheritance? like... class UpdatableTime: updated_at=Required(datetime.datetime) ...... class anotherClass(db.Entity,UpdatableTime): ......

Alexander
27.09.2018
21:51:48
This approach (when some attributes are defined inside a mixin class, but this class doesn't have a specific table and doesn't exist as a separate entity) is called abstract base classes. At this moment Pony does not support abstract base classes, but I think we should add them, it is easier than adding multiple-tables type of inheritance. Right now you need to duplicate attribute in all classes

Rozen
27.09.2018
21:52:41
alright

thanks!

Krzysztof
29.09.2018
19:48:10
Hello. One more question from me (I'm a PITA, I know): is it possible to check for entity type in query? For example, how can I do such a thing: select(b for b in BaseClass if type(b) == InheritedClass)? The _discriminator_ doesn't work inside a query.

I know that the above doesn't really make sense, because I could just do select(i for i in InheritedClass), but it's needed in more complicated cases.

OK, I found it, it seems like I can do: select(b for b in BaseClass if getattr(b, str(BaseClass._discriminator_attr_).split('.')[1]) == 'InheritedClass') But is there a better way?

I know I could just check for b.classtype, but it might fail if the discriminator is named differently.

Alexander
30.09.2018
04:11:16
Hi Krzysztof! Thanks for bugging me out, I just added support of isinstance in queries: https://github.com/ponyorm/pony/commit/f5e24f2743b4e1a298291a07f74144861b809cb4 Now you can write: select(b for b in BaseClass if isinstance(b, InheritedClass))

Google
Alexander
30.09.2018
04:21:54
It will be included in the next release, you can check out PonyORM from GitHub repository to use it right now

Matthew
30.09.2018
08:24:57
https://github.com/antoyo/tql this looks like it has had some inspiration from Pony

Permalink Bot
30.09.2018
08:25:04
https://github.com/antoyo/tql this looks like it has had some inspiration from Pony
Permanent link to the antoyo/tql project you mentioned. (?)

Krzysztof
30.09.2018
08:32:32
Thanks, @metaprogrammer, that was quick! :-)

Vitaliy
30.09.2018
08:43:26
Great! I also waited for this update. ? When should the next release be available?

Krzysztof
30.09.2018
08:50:05
@metaprogrammer, I'm away from the computer right now, but it seems like your assert in line 2497 will fail if the class has no derived objects. I don't feel this is right. I think that the following should pass in your test file: select(g.number for g in Group if isinstance(g, Group)). It would just feel more pythonic this way, I think.

If it already works and I don't see it, you should probably just add such test, just to be safe.

I'm sorry for complaining, don't get me wrong, you're doing a great job. :-)

Alexander
30.09.2018
09:06:02
Krzysztof, no need to apologize, I appreciate you feedback, it is on-point and constructive. Sometimes I make stupid errors, and It is great when someone reviews the code for errors I just added test you suggested. assert in 2497 will not fail, because in that case Pony recognizes that isinstance check makes no sense and replace discriminator check with dummy WHERE 1 = 1 expression (or with WHERE 0 = 1 for queries like select(p for p in Person if isinstance(s, Group)))

Krzysztof
30.09.2018
09:07:08
OK, that is great. Thanks once again! :-)

Alexander
30.09.2018
09:07:10
@vitalium I don't know yet when will be the next release date, I think around October 20. I want to add a bit more features in it.

Krzysztof
30.09.2018
15:00:32
@metaprogrammer Just one more thing you need to change in test_isinstance.py: rename one of the test_8 functions to test_9 (there is two of them). Except that, it's all great as always. :-)

ワスドフ(Wasdf)
01.10.2018
11:08:44
Hey, i have a question

Is there some way to get the information of an object attrs that is a Set or a referencr of another object outside a db_session? Currently i extract hand made all the info i need of an object and return a dict

Krzysztof
01.10.2018
11:13:06
It seems like your issue has one answer on StackOverflow (see bottom part, about “touching” the attributes): https://stackoverflow.com/questions/25719869/databasesessionisover-with-pony-orm-due-to-lazy-loading

Have you checked such solution? If you have, why wasn't it enough?

Oh, and there is the second answer that I missed, my bad. See second top answer, from @metaprogrammer, about the prefetch function.

In fact, you could consider both approaches and see which is a better fit.

ワスドフ(Wasdf)
01.10.2018
11:17:28
I thought that put the dbsession in top level was bad habit

Google
ワスドフ(Wasdf)
01.10.2018
11:19:04
but, if is the correct way, i tried it

Alexander
01.10.2018
11:21:19
Hi Wasdf! Yes, it is the correct way to wrap db_session around the entire processing, including template generation, etc. Krzysztof, thanks, I've fxed the typo in the test name

ワスドフ(Wasdf)
01.10.2018
11:42:40
It works well

Alexander
01.10.2018
11:42:52
?

ワスドフ(Wasdf)
01.10.2018
11:43:10
with prefetch, is there any way to get a Set of entities?

btw i have no problem with de db_session top level option xD

Alexander
01.10.2018
11:44:34
with prefetch, is there any way to get a Set of entities?
I think I don't understand what exactly you mean

ワスドフ(Wasdf)
01.10.2018
11:44:56
I think I don't understand what exactly you mean
Sure, my english is very bad, srry!

Alexander
01.10.2018
11:45:06
No problem

ワスドフ(Wasdf)
01.10.2018
11:52:11
``` class A(db.Entity): id = orm.PrimaryKey(int, auto=True) b = orm.Set(B) class B(db.Entity): id=orm.PrimaryKey(int, auto=True) a = orm.Set(A)

Страница 71 из 75