Matthew
but only one session at a time was using it
Matthew
So I think that having sessions which don't last for the lifetime of the process should fix it
Alexander
Yes. If you start db_session and perform some queries or updates, Pony starts database transaction. This transaction is not fully isolated, and some rows which were read in current transaction can be updated by another transactions which commit before the current transaction finishes. If you want to save some object, Pony checks if there are some columns which were READ by current transaction, and which values at this moment are different from the previously read values. In that case Pony throws UnrepeatableReadError, because updating this object can lead to overwriting some data which were changed by previously finished transaction
Matthew
That makes sense, thanks
Иван
What's wrong when you are using db_session in async code? will it initialize separate database connection for each coroutine when db_session used Or it will be 1 shared connection?
Anonymous
I just wanted to ask you guys why Telegram and not something else like, Slack for example.
Alexander
It will be 1 connection, because otherwise it can lead to situation when multiple concurrent connections hold database locks for a long period of time. I think at this moment it is hard to use Pony with async frameworks. Pony typically assumes that each db_session has separate transaction, but for async code it is hard to do separate transaction for each potentially long-lived concurrent db_session. Probably for async code we need to add some new transactionless mode, where each change commits immediately, and rollback is not possible
Anonymous
Why not?
Well, many. - We dont need to provide our Phone number to join Slack.. - There's a Web app, an Mobile app, and a Desktop App - There's many useful tools like pinning conversations to newcomers - Ability to have different channels in the same Workspace - APIs that enable cool CI/CD stuff, like having a Jenkins bot posting latest Build status to a specific Channel - Overall its a Developer-centered tool, instead of just a chat app. Dont get me wrong, I'm grateful for you guys not having chosing something like Whatsapp.
Matthew
It is probably too much work to switch to another service now
Matthew
You could start a slack group if you wanted though
Alexander
AFAIK free Slack does not keep entire chat history, and paid Slack account is not cheap ($6.67 per user per month)
Alexander
Also. it is not without its own problems, it seems https://medium.freecodecamp.org/so-yeah-we-tried-slack-and-we-deeply-regretted-it-391bcc714c81
Matthew
https://matrix.org/blog/index - this looks interesting for the future
Matthew
tl;dr: federated chat servers that speak json to each other
Anonymous
yeah, seems like they got quite the burn.. But freeCodeCamp is quite a big community.. I would ask if somebody tried HipChat This matrix.org seems interesting, never got my eyes on it before.
Anonymous
nevermind, I'll improve my research before doing further suggestions =-)
Alexey
Does anyone have experience with https://gitter.im ?
Alexey
Or https://www.discourse.org
Lucky
Well, many. - We dont need to provide our Phone number to join Slack.. - There's a Web app, an Mobile app, and a Desktop App - There's many useful tools like pinning conversations to newcomers - Ability to have different channels in the same Workspace - APIs that enable cool CI/CD stuff, like having a Jenkins bot posting latest Build status to a specific Channel - Overall its a Developer-centered tool, instead of just a chat app. Dont get me wrong, I'm grateful for you guys not having chosing something like Whatsapp.
- Phone number • but it isn't shared with other users, emails are easier to fake and abuse. - There's a Web app, an Mobile app, and a Desktop App • same, and the applications are all native and not only electron wrappers. - There's many useful tools like pinning conversations to newcomers • okey, but do you need to pin more than one post though? - Ability to have different channels in the same Workspace • I think that's not needed, also you can easily create another chat. - APIs that enable cool CI/CD stuff, like having a Jenkins bot posting latest Build status to a specific Channel • check out @githubBot, @Travis_ciBot... - Overall its a Developer-centered tool, instead of just a chat app. • I don't feel like this chat would be unsuited for the task so far. You can even link to a message https://t.me/ponyorm/9527. Also, Telegram apps don't need 2GB ram though — Just kidding, lol. Dont get me wrong, I'm grateful for you guys not having chosing something like Whatsapp. • that would have been horrible, glad that didn't happen. You can also get your help on stackoverflow, or post issues at GitHub.
Lucky
https://matrix.org/blog/index - this looks interesting for the future
There is a telegram bridge, so it could be just added, and you could either chat here or at matrix. t.me/mautrix_telegram
Lucky
Alexey @metaprogrammer That's spam
Lucky
If you guys need another admin to handle this stuff, I'd love to help out.
Lucky
@metaprogrammer, spam again
Alexander
If you guys need another admin to handle this stuff, I'd love to help out.
Account that created this chat is deleted, so these privileges cannot be granted.
Lucky
Account that created this chat is deleted, so these privileges cannot be granted.
Oh boy, I have that issue in one group as well. Happily you guys have the twitter handle, and stuff, so you could apply to Telegram Support.
Lucky
If you apply to the Support they can help in moving t.me/PonyORM to a new channel:
Lucky
So you could either continue with an admin only... or in case you have exactly the same username as a social identity (Twitter+FB or Instagram, two of them are enough), Telegram may be able to move the username to a new channel.
Alexey
Oh, I see Thanks @luckydonald
banteg
hey, really nice pythonic orm you got there. one problem i bumped into as a first time user was finding info on how to create a unique index. i had to read the api section on creating entities back to back to discover composite_key. i guess adding words "unique index" there wouldn't hurt for discoverability.
banteg
banteg
also, what's the best practice on batch inserts? will this be done in one query? with db_session: for thing in things: Thing(**thing)
Matthew
That will not be done in one query but will be done in one session. If you put sql_debug(True) at the start you can see exactly what is happening
banteg
oh, i see now, thanks for the tip
Jacob
What are the units for the "size" of int entities?
Jacob
8,16,24,32,64 - bits? bytes? something else?
Alexander
it's bits - 8, 16, 32, 64
Jacob
I'm trying to map an existing mysql db, and so when I saw tinyint(4) I was looking for something of length 4. Googling a bit, I see that the 4 in parentheses is only for display. So, does Pony care about the m in int(m) or tinyint(m)?
Alexander
No, Pony ignores the number of digits to display, it just treats int with size=8 as tinyint
Jacob
ok.
Jacob
/me deletes sql_type from the models...
Jacob
Is there something like size for str? the editor seems to put the max length as an arg instead of a kwarg.
Jacob
It looks like str is where defining the sql_type is more helpful: to distinguish CHAR(1) vs VARCHAR(1) right?
Alexander
Yes, but if you are working with pre-existing tables and don’t plan to generate CREATE TABLE commands it should be not important, sql_type is used for CREATE TABLE only. For str you can use max_len keyword argument instead of positional argument, we probably need to add it to editor too
Jacob
Cool. I couldn't find any documentation about max_len or using that arg, so I wasn't sure.
Jacob
Thanks for clarifying.
Jacob
Can I add a one-way relationship, ie add a reference to another entity without the "reverse attribute" on that entity?
Jacob
Because I'm going to have around 100 tables that all reference 2 other tables, and it's going to be really difficult to read those two tables if they have to have so many reverse attributes.
Jacob
(gotta love legacy)
Alexander
At this moment it is required to have attributes on both sides, we'll change it later
Jacob
ok
Jacob
For a many-to-many relationship, I can specify the intermediate table name with Set("Two", table="uglyname") and Set(One, table="uglyname"). Do I need to specify table= on both sides?
Alexander
No, it is enough to do it on one side
Jacob
Also, I think I need to use reverse_column (instead of column) to specify the column names in the intermediate table. But which column do I specify? eg for the One<>Two relationship, on entity One would the reverse_column be the name of the intermediate's column referring to One (say OneID)?
Alexander
You need to specify it as: class Student(db.Entity): courses = Set(Course, column="course_id") class Course(db.Entity): students = Set(Student, column="student_id") It looks "intuitively", but actually it's weird, because it is the other column that actually used for foreign key relationship. Maybe it was better to define it the other way around, despite it "non-intuitive" looking
Jacob
So what is reverse_column then?
Alexander
I mistyped )
Alexander
The reverse_column is the way to specify both columns on one side of relationship: class Student(db.Entity): courses = Set(Course, column="course_id", reverse_column="student_id") class Course(db.Entity): students = Set(Student)
Jacob
I think using column like that is fine. I could see it both ways, that's why I asked.
Jacob
Cool. I'm going to use column and reverse_column then. That looks much nicer :)
Jacob
(at least in the context of what I'm working with now)
Jacob
I'm adding a Converter. What's the difference between py2sql and val2dbval? between sql2py and dbval2val?
Anzor
Hi all! Not sure how to ask a question the right way, but how do deal with datetime awareness when using postgres?
Matthew
Alexander
For each attribute Pony may keep val and dbval. dbval is what read from database, and used for optimistic checks ("is attribute db value still the same as what was read originally"). Val is what user can get/set. For example, for SQLite JSON attribute dbval is JSON serialized as string, and val is JSON unpacked to dict subclass (modified to track item changes to save them at the end of transaction). So, when value is read from database the flow is column (from database cursor) -> dbval (from sql2py) -> val (from dbval2val) And when the value is asiigned to attribute and then saved to database the flow is val -> dbval (from val2dbval) -> cursor argument (from py2sql) For most types, val2dbval and dbval2val does not change value.
Jacob
https://gist.github.com/cognifloyd/21ca9f9e0153cf489590af74a8273e6a
Jacob
In this gist, I'm trying to create a bool that is stored in the DB as "Y" when True, and "N" if false. When reading from the DB, NULL also counts as false.
Jacob
But pony.orm.ormtypes.normalize_type isn't allowing my custom YNBool through saying "Unsupport type 'YNBool'"
Jacob
How can I add my custom type?
Jacob
The legacy db I'm working with is MySQL in production, but I use sqlite for testing.
Jacob
(if that makes a difference)
Alexander
Pony types and converters are not designed to be easily extendable by a third-party code, because it is a non-trivial task (for example, it requires non-trivial code in SQLTranslator which is often missed when someone tries to write its own converter) It seems that in your case what you need is not a new type, but some changes in BoolConverter, like a new option to allow it to use CHAR column instead of INT to store values Maybe you can fork PonyORM, change its base BoolConverter (and maybe its subclasses for some database providers) to support CHAR columns, and than if it works good you can make a pool request to add this changes back to Pony
Jacob
@metaprogrammer Yeah. It looks like I would need to do something in sql translation. I tried a modified BoolConverter that uses either sql2py/py2sql or dbval2val/val2dbval (I updated the gist), and both methods works for saving Y/N in db and returning True/False, but I can't do select(t for t in db.Thing if not t.deleted) where deleted is this YN boolean. Instead I have to do if t.deleted != 'Y'