@ponyorm

Страница 42 из 75
Roman
26.09.2017
15:36:06
No. We'll fix it tomorrow

joery
26.09.2017
21:40:39
Another thing I noticed is that the 'Max length' property does not work

Alexander
26.09.2017
22:17:56
Doesn't work in Pony or designer?

joery
26.09.2017
22:18:19
Google
Henri
28.09.2017
07:56:10
/help@bonbot

Bonbot
28.09.2017
07:56:11
/help@bonbot
Sending help to you privately.

Matthew
30.09.2017
10:43:00
Hi, any thoughts on Pony implementing BETWEEN for postgres?

I realise that it is the save as a >= x AND a <= y, that is not in pony either though

Alexander
30.09.2017
11:35:22
It actually looks easy to implement, I mean between(a, x, y). I agree it may be convenient, I'll try to add it the other day

Matthew
30.09.2017
11:51:52
it looks like it exists in sqlite and mysql as well

there is also NOT BETWEEN

Matthew
30.09.2017
11:54:16
wouldn't that turn into an IN (13, 14) SQL currently?

btw this is also useful for dates / datetimes as well as numbers

Luckydonald
30.09.2017
11:55:42
wouldn't that turn into an IN (13, 14) SQL currently?
I have no idea, just adding my two cents

Matthew
30.09.2017
11:56:48
select(u for u in User if u.id in range(1, 10))[ : ]

turns into

Google
Matthew
30.09.2017
11:57:00
... FROM "user" "u" WHERE "u"."id" IN (%(p1)s, %(p2)s, %(p3)s, %(p4)s, %(p5)s, %(p6)s, %(p7)s, %(p8)s, %(p9)s) {'p1':1, 'p2':2, 'p3':3, 'p4':4, 'p5':5, 'p6':6, 'p7':7, 'p8':8, 'p9':9}

Alexander
30.09.2017
12:04:48
Theoretically it is possible to translate range(i, j) to BETWEEN too. But I'm not sure we need, because range is limited - its arguments should be integers. I think it is better to add between function to pony.utils and learn pony to translate it to SQL.

I added between and pushed to GitHub: from pony.orm.examples.university1 import * select(s for s in Student if between(s.gpa, 3.5, 4.5))[:] select(s for s in Student if not between(s.gpa, 3.5, 4.5))[:]

Matthew
30.09.2017
14:12:34
Cool! Will it work with dates / datetimes?

Alexander
30.09.2017
14:13:25
I think yes. It should work with any types for which you can use SQL BETWEEN expression

Matthew
30.09.2017
14:15:10
and is "not between" implicitly supported?

Alexander
30.09.2017
14:15:17
yes

Matthew
30.09.2017
14:15:55
+def between(a, x, y): + return a <= x <= y +

Does that mean that select(z for z in Z in z.a <= x <= z.y) will work with Pony?

Alexander
30.09.2017
14:17:47
At this moment - no, we need to add support to decompiler, it is a bit untrivial. The body of between function is not used during translation, it just to be able to use it in Python

Matthew
30.09.2017
14:18:01
ah ok

Alexander
30.09.2017
14:18:10
SQLite: >>> select(s for s in Student if not between(s.dob, date(1995, 1, 1), date(1998, 1, 1)))[:] SELECT "s"."id", "s"."name", "s"."dob", "s"."tel", "s"."gpa", "s"."group" FROM "Student" "s" WHERE "s"."dob" NOT BETWEEN '1995-01-01' AND '1998-01-01' [Student[1], Student[2], Student[3], Student[4], Student[5], Student[6], Student[7]] >>>

Matthew
30.09.2017
14:18:19
Cool :)

Pony is becoming very solid now

in terms of features and reliability

Alexander
30.09.2017
14:19:21
I plan to work on Pony until New year and add many missing features - migrations, upserts, etc.

Matthew
30.09.2017
14:19:39
How could an upsert look in Pony?

Alexander
30.09.2017
14:21:36
obj = MyObject.create_or_update(foo=1, bar=2) and parent_object.some_collection.create_or_update(foo=1, bar=2)

Matthew
30.09.2017
14:23:26
Cool, I often do x = X.get(foo=1) or X(foo=1) (or kwargs passed to both), but I imagine upsert would be better

Alexander
30.09.2017
14:28:14
The main benefit of upsert is atomicity. X.get(foo=1) or X(foo=1) sometimes can raise an exception, if another transaction was able to insert object in between

Google
Federico
30.09.2017
18:14:41
Hello guys, I wonder if the source code for the online editor Is available , or if you could tell me which js libraries is using to render the diagrams and svg connections. I'm trying to start an open source project to do a similar think for Django models and it would be very instructive. Thanks

Alexey
30.09.2017
18:22:16
Hi Federico, we didn't open source the editor code. We use reactjs, mobx and svg. The next week we are releasing the editor for Django - want to see if it will be useful for Django community

Federico
30.09.2017
18:32:17
Good to hear that, I'll stay tuned for that. I also wanted to generate the code to wire up those models to api views with django rest or graphene, so perhaps I'll also try to build the diagram myself. Thanks!

Alexey
30.09.2017
18:34:44
Great! Will let you know once we deploy it. The only thing that I'm afraid will not be very straitforward is that we have to split the Django models declarations and the behavior the way it is described here https://bradmontgomery.net/blog/django-models-mixins-for-cleaner-code/

because each models update will rewrite the file, and having the model methods incorporated into the models is not convenient

Shawn
02.10.2017
01:19:04
is there a way in pony to detect duplicate records on insert? such as INSERT INTO the_table (id, column_1, column_2) VALUES (1, 'A', 'X'), (2, 'B', 'Y'), (3, 'C', 'Z') ON CONFLICT (id) DO UPDATE SET column_1 = excluded.column_1, column_2 = excluded.column_2;

using postgres

Micaiah
02.10.2017
02:17:15
Does Pony have something like table_entry.update(**newdata)

Alexander
02.10.2017
02:21:59
Does Pony have something like table_entry.update(**newdata)
newdata = {'foo': 1, 'bar': 2} some_entity.set(**newdata) If you need to forse immediate execution of sql command, you can apply flush() function or db.flush() method

Александр
03.10.2017
23:33:33
По русски здесь говорят?

Alexander
03.10.2017
23:35:15
No, please speak in English

Александр
03.10.2017
23:35:31
Ok

Matthew
06.10.2017
13:21:15
Is there any reason why an after_insert method on a pony entity would not fire in a flask application?

the objects are successfully created in the database, but the after_insert isn't called (verified with a print statement on first line of after_insert method)

Alexander
06.10.2017
13:24:35
Can you define after_update method too and check if it is called instead?

Matthew
06.10.2017
13:25:23
Should it be called on the creation of a new object?

after_insert seems to work in other parts of the same project

Google
Matthew
06.10.2017
13:31:24
i think this is not pony's fault :)

Alexander
06.10.2017
13:31:26
It should work. The behavior that you described looks like a bug. It was my guess that maybe another object X was able to update the object Y you speak about in its X.after_insert hook, and than Y.after_update hook was invoked instead of Y.after_insert. It just a wild guess. Maybe the problem lies somewhere else

Matthew
06.10.2017
13:31:35
after mentioning it, i noticed that the method was being called

Alexander
06.10.2017
13:31:54
Ah, ok. Good

Matthew
07.10.2017
10:46:38
is after_insert always called after commit (either explicit or implicit) ? I am getting background jobs created in an after_insert unable to find newly created objects (which had after_insert fired) running in another process

The job does get a numeric ID though

which implies that the commit has happened

The workers are python-rq

Luckydonald
07.10.2017
11:28:05
Can I do mass-update statements in pony? I've got Stickers in a Pack, having tl_ids. I have a list of stickers which should not be set to deleted, namely still_existing_sticker_tl_ids=set(123,456,789) SQL should be something like this: """ UPDATE sticker SET deleted=true WHERE sticker.pack == %db_pack% AND sticker.tl_id NOT IN (%still_existing_sticker_tl_ids%) """ I think the Pony orm select is roughly query = orm.select(db_sticker for db_sticker in db_pack.stickers if db_sticker.tl_id not in still_existing_sticker_tl_ids)

Matthew
07.10.2017
11:29:03
you can do query.delete(bulk=True)

Luckydonald
07.10.2017
11:29:26
I set a delete flag, not actually remove them

Matthew
07.10.2017
11:29:33
oh sorry

Luckydonald
07.10.2017
11:29:39
No problem :D

Matthew
07.10.2017
11:29:42
afaik no that's not currently possible in pony

Luckydonald
07.10.2017
11:30:33
So there is no select(...).update(field=lel)

Matthew
07.10.2017
11:30:47
not that I know of

When pony does a query (using postgres), using a long running session, is it guaranteed to pick up objects which have just been committed in another session?

Luckydonald
07.10.2017
13:27:52
Maybe using orm.commit?

Matthew
07.10.2017
13:28:31
I do this in one session: X(a=1); commit() Then in another existing session, I do X.get(id=1)

where 1 is the ID of the object just created

Google
Matthew
07.10.2017
13:28:42
and then it doesn't find it

I have recently discovered this as an issue because the work queue is more likely to be empty, due to efficiency improvements

could serializable=True be the answer?

alternative could be scheduling work in say 10 seconds but that feels ugly

joery
07.10.2017
14:05:02


Alexander
08.10.2017
19:39:29
Hi joery! Actually, we changed free plan to allow copying of other users' public diagrams, but the code contains a bug which disallows it right now. We will fix it on Monday, and after that the user with free plan will be able to copy diagrams of other users

Hi Matthew! The after_insert hook works before commit. At this moment, we already know IDs of newly created objects, but other transactions still canot see these objects. If you want to pass IDs to another process, you probably need to accumulate them in some local list, and send that list to another process after the commit is finished.

Matthew
08.10.2017
19:49:32
ah suddenly it all makes sense :)

Alexander
08.10.2017
19:49:36
@luckydonald I have a plan to add mass update operaton with the followng syntax in the future: update(obj.set(foo=x, bar=y) for obj in MyObject if obj.baz == z) But the problem with mass update is that it happens inside the database, and pony does not know which objects were actually changed. Because of this, pony cannot update cached in-memory information about objects, and also cannot invoke after_update hooks. This complicates mass update implementation

Matthew
08.10.2017
19:50:09
would it be possible in theory to have an after_commit hook?

Alexander
08.10.2017
19:53:00
Yes, I think it is possible. Maybe we need to change the current hooks API to something more general

Matthew
08.10.2017
19:53:31
why is after_insert setup to run before the commit?

Alexander
08.10.2017
19:55:52
Because typical use-case is to update some other objects during the same atomic transaction, like: class Student(db.Entity): name = Required(str) group = Optional(Group) def after_insert(self): if self.group is not None: self.group.count_of_students += 1

Matthew
08.10.2017
19:59:53
ah ok

Alexander
08.10.2017
20:01:07
I think it is a non-trivial question when is the best moment to invoke a hook: right after SQL command is executed, after all previously modified objects are flushed to the database, or after the transaction is finished

Currently it is the second: after flush() is completed

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