Re: [sqlalchemy] Re: Conditional insert in one transaction

2021-02-04 Thread Vitaly Kruglikov
. I also came across a nice graphical illustration of the race condition associated with concurrent INSERT here: http://rachbelaid.com/handling-race-condition-insert-with-sqlalchemy/ On Thursday, February 4, 2021 at 5:42:40 PM UTC-8 Vitaly Kruglikov wrote: > Thanks Mike! I followed up on y

Re: [sqlalchemy] Re: Conditional insert in one transaction

2021-02-04 Thread Vitaly Kruglikov
Thanks Mike! I followed up on your suggestion concerning savepoints and came up with the following code snippet. Does this look right to you? ``` try: with orm_session.begin_nested(): orm_session.add(record) except psycopg2.errors.UniqueViolation as error: # or is it

Re: [sqlalchemy] Re: Conditional insert in one transaction

2021-02-03 Thread Vitaly Kruglikov
How can the query/merge or query/add be performed atomically? What would happen if between the two calls another process inserted a row with the same unique key? Wouldn't the `s.merge()` then trigger a `psycopg2.errors.UniqueViolation` exception (in postgres case) when the new row insert is

[sqlalchemy] How to identify unique constraint violation without dependency on a specific database driver?

2020-09-18 Thread Vitaly Kruglikov
My table has a unique index on the column named "tag". When I attempt to insert a row with a tag value that already exists in the table, sqlalchemy raises the generic exception `IntegrityError`. `IntegrityError` may be raised for various scenarios, including Foreign Key Violation and Unique

Re: [sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
ing else' > 4 unique_id = id(unique) 5 6 TypeError: 'str' object is not callable ``` On Saturday, August 22, 2020 at 8:09:19 AM UTC-7 Richard Damon wrote: > On 8/22/20 10:46 AM, Vitaly Kruglikov wrote: > > I suspect this has something to do with the combination of t

[sqlalchemy] Re: ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
Please note, that I posted, then deleted a message with the same subject in order to correct some relevant information, and this post replaces the one I deleted. On Saturday, August 22, 2020 at 7:43:42 AM UTC-7 Vitaly Kruglikov wrote: > Dear all, > > I am using: > sqlalchemy==1.3.1

[sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id.` when I run the following insert

2020-08-22 Thread Vitaly Kruglikov
Dear all, I am using: sqlalchemy==1.3.18 psycopg2==2.8.4 connection url schema: "postgresql+psycopg2://..." postgres 10.x My code looks like this: ``` _AutomapBase = automap.automap_base() class Model1(_AutomapBase): __tablename__ = 'model1" id_ = sa.Column('id', sa.Integer,

[sqlalchemy] ArgumentError: Only one Column may be marked autoincrement=True, found both id and id

2020-08-21 Thread Vitaly Kruglikov
Dear all, I am using: sqlalchemy==1.3.18 psycopg2==2.8.4 connection url schema: "postgresql+psycopg2://..." postgres 10.x when I define an explicit AutomapBase-derived model for 'sqa_global_context' table with only the primary key, I expected that running

Re: [sqlalchemy] `Base.prepare()` doesn't backfill missing columns and relationships in AutomapBase-derived models

2020-08-18 Thread Vitaly Kruglikov
bjects as the one you are creating with SqaGlobalContext > will not be affected. > > > > On Tue, Aug 18, 2020, at 1:59 PM, Vitaly Kruglikov wrote: > > Dear all, > > I am using: > sqlalchemy==1.3.18 > psycopg2==2.8.4 > connection url schema: "postgresql+ps

[sqlalchemy] Re: `Base.prepare()` doesn't backfill missing columns and relationships in AutomapBase-derived models

2020-08-18 Thread Vitaly Kruglikov
I just noticed a TYPO - but google groups doesn't let me edit my post. In a couple of places in my post, I accidentally entered `sqa_global_context` as the table name instead of `ewf_sqa_global_context`. But in actual code that I am executing, it's `ewf_sqa_global_context` everywhere. --

[sqlalchemy] `Base.prepare()` doesn't backfill missing columns and relationships in AutomapBase-derived models

2020-08-18 Thread Vitaly Kruglikov
Dear all, I am using: sqlalchemy==1.3.18 psycopg2==2.8.4 connection url schema: "postgresql+psycopg2://..." postgres 10.x when I define an explicit AutomapBase-derived model for 'sqa_global_context' table with only the primary key, I expected that running