@ponyorm

Страница 41 из 75
Alexander
07.09.2017
15:04:24
It seems that the bug is not in Pony. I tested on 0.7.2 and master, and the following code works without any problem: >>> from pony.orm.examples.university1 import * >>> select(s for s in Student if raw_sql('s.id % 4') == 0).random(5)

Matthew
07.09.2017
15:05:13
that example also works for me, that is weird

Alexander
07.09.2017
15:05:46
Maybe you can show traceback of your error

I was able to reproduce. The reason for the error is, PostgreSQL psycopg2 driver uses % symbols to represent query parameters, so in PostgreSQL it is necessary to double % sign inside RawSQL expression: select(u for u in User if raw_sql("u.id %% 4") == 0).random(5) It seems that without native Pony support of modulo division its using is a bit cumbersome. Probably we need to add it sooner

Google
Matthew
07.09.2017
15:23:29
Thank you very much!

was the pony example using sqlite?

Alexander
07.09.2017
15:23:52
Yes, by default it uses SQLite

Matthew
07.09.2017
15:24:20
i can confirm double %% works

Alexander
07.09.2017
18:15:35
Now you can use native modulo division for all databases we support. select(x for x in X if x.id % 1337 == 0)

Using GitHub version ofc.

Alexander
07.09.2017
18:16:25
Will be included in the next release

Matthew
07.09.2017
19:11:33
great :D

Xunto
07.09.2017
19:12:18
Good. I need also string.strip :D

Matthew
07.09.2017
19:12:34
For what use case?

Xunto
07.09.2017
19:13:22
For stupid legacy database that store array like this "1 2 3"

Alexander
07.09.2017
19:13:44
We already support strip method. Maybe you mean split

Xunto
07.09.2017
19:14:16
Oh, yeah. My bad.

Google
Xunto
07.09.2017
19:15:14
It's not really a feature request as it's not really needed by everyone

May be I'll do it myself someday.

Alexander
07.09.2017
19:16:27
Ok. We can add it if you suggest how to translate it to SQL

Alexander
07.09.2017
19:18:53
sqlite3.create_function() will translate any your wish

Alexander
07.09.2017
19:20:09
It is not as easy even for SQLite, because you need to return array of strings from this function

Matthew
07.09.2017
19:20:48
Why not just do it in python?

Xunto
07.09.2017
19:23:40
The problem is I need to search in them. I used to do "if number in ugly_string_array" it was enough... but... you know. There can be collisions the future.

In python I would need to itterate trough quite big amount of record. But still I can itterate after using "in"... but it's as ugly as database structure itself :D

Alexander
07.09.2017
19:26:50
You can search using LIKE operator if string components are separated properly. class Article(db.Entity): name = Required(str) tags = Optional(str) ... with db_session: a1 = Article(name='Article1', tags='*foo*bar*baz*') ... with db_session: baz_articles = Article.select(lambda a: '*baz*' in a.tags)

Xunto
07.09.2017
19:27:36
Hmm. Interesting.

@
08.09.2017
22:28:01
hey guys. I'm new to PonyORM and SQL in general. I've been browsing the documentation, trying to decide between sqlalchemy and pony, and I noticed there is no apparent way to do database migrations (ie. /w Alembic). What is the best practice around this?

@
08.09.2017
22:46:36
cool. I'll play with that. Is there any ETA on official migration tool?

Luckydonald
08.09.2017
22:58:35
Should be here already since quite some time, but It seems to be delayed.

Alexander
08.09.2017
23:01:29
Yes. There are good reasons for that.

I mean delay.

Luckydonald
08.09.2017
23:01:48
Please elaborate

Alexander
08.09.2017
23:02:52
Im not sure is that super secret inside info or not. But we keep work on them.

Luckydonald
08.09.2017
23:03:49
Uhhh. Seeeeeeeeecrets!

Alexander
08.09.2017
23:03:53
Like: migrations that we have now is not that thing we really want to release.

Google
@
08.09.2017
23:17:49
what in your opinion is the hardest thing about migrations?

Alexander
08.09.2017
23:23:46
In my - merge migration branches.

Luckydonald
08.09.2017
23:35:21
Hah, merging branches always is fun

Matthew
11.09.2017
11:12:53
pony.orm.core.OptimisticCheckError: Object User[x] was updated outside of current transaction - would it be possible to expand this error message to show which attribute(s) were updated?

then I can know which can be marked as optimistic

Alexander
11.09.2017
11:21:21
It is not easy to do. If a program retrieves an object with specific id value, read attributes b, c and d and then update attributes a and b, Pony will send a query which looks like UPDATE t1 SET a = <new_a>, b = <new_b> WHERE id = <id> AND b = <prev_b> AND c = <prev_c> AND d = <prev_d> And then Pony checks the number of rows which were updated. It may be 1 or 0. Zero means that some attribute where changed, but it is hard to say which exactly. Maybe in this case we can do additional select in order to retrieve new attribute values

I'm not sure that marking attribute as not optimistic is correct solution, because this way you just hide some lost update

Matthew
12.09.2017
09:33:23
In this case, I am not editing the object apart from a single attribute, a "date" type, is there a way to ignore all of the other attributes changing?

this is a very CPU intensive task, so redoing it isn't ideal

Maybe catching the OptimisticCheckError, then retrying that single attribute update?

I don't think I want to lock the object, as this would stop users from doing other things during the multiple minute background processing job

Alexander
12.09.2017
10:00:46
Maybe we can add new option to db_session, something like: with db_session(optimistic=False): ...

This option will turn off optimistic checks. It may lead to lost updates, so programmer need to be careful about when to use it

Matthew
12.09.2017
10:12:01
That sounds like it could work, but maybe I'm missing something and Pony already allows this?

I don't think restarting the whole transaction makes sense

the use case is doing a lot of reads from the database, writing some computed data to redis as a cache, then marking that user object as computed for today

Since the modulus now works, there are multiple processes doing this, so there are a lot more optimistic errors

Alexander
12.09.2017
11:25:01
I think you can attempt the following: 1) Mark that single datetime attribute as volatile. It is possible that you have concurrent processes that tries to do the same calculation on the same object in parallel. You can also add some in_process volatile flag to object which will prevent concurrent processes to start the same calculation for object that is already processing. 2) If concurrent processes actually changes some attributes beside that single datetime attribute, then I'm not sure your redis cache contains valid non-obsolete data. It looks suspicious to me. But if you think that all is OK, you can prevent optimistic errors by extracting that single datetime attribute to another object. Then you entities may look like: class MyObject(db.Entity): id = PrimaryKey(int, auto=True) foo = Required(int) bar = Optional(str) object_state = Optional(lambda: ObjectState) class ObjectState(db.Entity): id = PrimaryKey(int, auto=True) object = Required(MyObject, unique=True) in_process = Required(bool, default=False) processed_at = Optional(datetime) Then, you should create objects in pairs: obj = MyObject(foo=10, bar='hello') obj_state = ObjectState(object=obj) And then you can process object as following: with db_session: query = MyObject.select(lambda obj: obj.id % N == M) query = query.filter(obj.foo == X) query = query.filter(lambda obj: not obj.object_state.in_process and ( obj.processed_at is None or obj.processed_at < datetime.now() - timedelta(days=1))) objects_to_process = query[:] for obj in objects_to_process: obj.object_state.in_process = True commit() for obj in object_to_process: make_some_complex_caclulation(obj) obj.object_state.in_process = False obj.object_state.processed_at = datetime.now() In that case, you read foo and bar attributes from obj and write in_process and processed_at attributes to obj_state, so concurrent errors should not appear

But in any case I need to do the following: 1) Change Pony code so if you start db_session with serializable=True option (which means full isolation) than optimistic checks are not added to queries. 2) In case of optimistic errors, make additional query to database in order to determine which attribute was changed

Richie
14.09.2017
06:08:38
./

Google
Admin


Alexander
14.09.2017
14:34:21
Hola.

Matthew
22.09.2017
19:19:57
Has anyone tried pony with the postgres 10 betas yet? I plan on doing so soon and wanted to know if there are any problems

Luckydonald
22.09.2017
19:22:03
Matthew
22.09.2017
19:22:47
Parallel queries is the big advantage I see

https://news.ycombinator.com/item?id=15306398

Luckydonald
22.09.2017
19:31:44
/translate

@akozlovsky can I add @bonbot for the /translate command and for the github permalinks?

Alexander
22.09.2017
19:36:14
/translate
It seems missclick. Nvm

Vitalii
22.09.2017
19:37:20
/translate
Sorry for that, wrong tab=)

Luckydonald
22.09.2017
19:37:33
Ah, ok xD Point still stays xD

Alexander
22.09.2017
22:47:14
Alexander
23.09.2017
00:13:00
Any docs of usage?

Святослав
23.09.2017
04:21:10
/translate@bonbot

Bonbot
23.09.2017
04:21:11
/translate@bonbot
Please provide a text to translate. Either use /translate some text goes here or reply `/translate` to some text message.

Luckydonald
23.09.2017
08:59:36
Any docs of usage?
It will tell you with /help xD

stsouko
23.09.2017
16:33:50
/help@bonbot

Bonbot
23.09.2017
16:33:52
/help@bonbot
Sending help to you privately.

Micaiah
24.09.2017
22:40:40
Anyone have issues with pony and gunicorn?

My app is failing if I import my models (which includes binding to the database)

Google
Alexander
24.09.2017
22:43:03
With what exception?

Micaiah
24.09.2017
22:52:49
Nevermind, it was a dumb syntax error :/

joery
26.09.2017
14:02:58
Hi



Vitalii
26.09.2017
14:04:45
definitely not, please give a link to your diagram

joery
26.09.2017
14:06:18
https://editor.ponyorm.com/user/joery/test/designer

I always happens, after you add the first entity

Vitalii
26.09.2017
14:25:57
it is fixed now

joery
26.09.2017
14:26:32
Awesome! Thank you

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