Re: [sqlalchemy] session.merge() and detecting insertions and updates within the context of an HTTP handler

2019-01-11 Thread HP3
Thank you very much Mike! with session.no_autoflush: > obj = session.merge(my_thing) > for r in session.new: > > for r in session.dirty: > ... > session.new is showing the newly added :) I'll need to experiment more to make sure all my cases are covered.

[sqlalchemy] session.merge() and detecting insertions and updates within the context of an HTTP handler

2019-01-11 Thread HP3
Hello all, I'm using `session.merge()` within an HTTP handler, I would like to know which objects have been newly added and which ones have been modified after `merge()` completes. Bare with me please ... I know there are `before_flush`, etc. events exactly for this scenario but I **only**

Re: online vs offline produce different "python stack traces" and general question

2018-09-07 Thread HP3
> > Perfect, that's what I thought. Thanks a lot Mike! -- You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to

Re: online vs offline produce different "python stack traces" and general question

2018-09-06 Thread HP3
Thank you very much Mike! The older baseline is on v0.9.7 but I am not sure if I can bump it up 'blindly' ... I think all constructs are "vanilla" so maybe it's safe. In my v0.9.7 based model, I used history_meta recipe (slightly modified though). At any rate, after fudging around with some

online vs offline produce different "python stack traces" and general question

2018-09-06 Thread HP3
iffer between online (first stack) and offline (second). Hence, this post.* *Does that make sense?* *Question: are online migrations run within a single transaction or not?* *Thanks!!!* $ alembic upgrade head /Users/hp3/.pyenv/versions/2.7.14/envs/server_py2/lib/python2.7/site- packages/psyc

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
Thank you both With `before_cursor_execute` I am able to log each Connection, Cursor and context instance. I see that every worker is doing its thing and the Connection instance is always different for each SQL statement Also, each SQL has its own distinct

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
> > @HP3 just to test this, i would try adding a slightly different connection > string or argument to the celery connection. e.g. create a different user, > or toss in a config argument that doesn't affect your code. if the error > stops, that's most-likely the reason w

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
Thank you Mike! That's very useful. I can see which engine & worker is emitting each SQL statement (I had to bypass the usage of 'pyramid_celery` so all logging settings would "stick"). *Is there a way to identify every engine instance?* *Every celery worker is creating its own

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
> > > I verified that the failure checkpoint is not being persisted either when I raise an exception after 'do something' checkpoint. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal,

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
I'm confused about what you said about the underlined connection: I am creating 2 different engines. Why would both share the same connection? FYI - I just tried without zope.sqlalchemy and got a slightly different result: My concurrent transactions are no longer failing with

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-25 Thread HP3
Thank you Jonathan, This is how I create both engine/session pairs: from sqlalchemy import engine_from_config from sqlalchemy.orm import sessionmaker import zope.sqlalchemy class DBTask(app.task) _engine = None _domain_model_session = None def checkpoint(self, label): *#

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-22 Thread HP3
No dice! I verified that engines and sessions are created after fork. By hijacking celery logging, verified each worker had its own transaction and session. The SQL logs I described above are indeed accurate and belong to the same worker. -- SQLAlchemy - The Python SQL Toolkit and Object

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-22 Thread HP3
> > Is there a chance there is a query/connection being made between the > initialization and worker process? > Hmmm ... I am using celery task inheritance (http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance) with `@property`s for domain model engine and domain

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-22 Thread HP3
I added logging to `session.transaction` and `session.transaction.parent` (til parent=None) and `session.transaction.nested` and they all seemed to be different, never nested, never subtransaction. No hint there. I modified my code slightly by adding a new

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-22 Thread HP3
is affecting the behavior of my `celery_state_session`? > > On Thursday, June 21, 2018 at 9:34:33 PM UTC-5, Jonathan Vanasco wrote: > > > On Thursday, June 21, 2018 at 10:02:27 PM UTC-4, HP3 wrote: >> >> What's the correct way to create a session that is not automatically >> b

Re: [sqlalchemy] Multiple sessions same thread - How to?

2018-06-21 Thread HP3
t. Just setting an attribute value does not send any SQL. > > On Thu, Jun 21, 2018, 7:22 PM HP3 > > wrote: > >> Hello all: >> >> Within a celery task, I need to have 2 unrelated sessions that can >> commit/rollback independently of each other: >> One sessio

[sqlalchemy] Multiple sessions same thread - How to?

2018-06-21 Thread HP3
Hello all: Within a celery task, I need to have 2 unrelated sessions that can commit/rollback independently of each other: One session (`domain_model_session`) performs vanilla domain model operations and the other (`celery_state_session`) is to persist the state of the celery task itself

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-13 Thread HP3
Hmmm - makes sense. I'll switch to plain @property instead. Thank you very much again Mike! On Tuesday, June 12, 2018 at 3:32:35 PM UTC-5, Mike Bayer wrote: > > On Tue, Jun 12, 2018 at 12:20 PM, HP3 > > wrote: > > Hmmm > > > > In my testing, the class le

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-12 Thread HP3
cally" populated but it never worked. On Tuesday, June 12, 2018 at 10:19:35 AM UTC-5, Mike Bayer wrote: > > > > On Tue, Jun 12, 2018, 10:20 AM HP3 > > wrote: > >> Hmmm >> >> I didn't use the @hybrid_property.expression for anything else so I ende

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-12 Thread HP3
ayer wrote: > > That's fine but you should probably use a normal @property for that, > unless you are still making use of a separate "expression" portion. > > On Fri, Jun 8, 2018, 8:04 PM HP3 > > wrote: > >> I ended up settling for this: >&

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-08 Thread HP3
(P2B) .filter(P2B.id == cte.c.parent_id) ) return session.query(cte).all() And each time I call child.ancestors, the SQL CTE RECURSIVE is issued (of course!?) Thanks again for all your help Mike! On Friday, June 8, 2018 at 6:39:05 PM UTC-5, HP3 wrote: > &g

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-08 Thread HP3
? On Friday, June 8, 2018 at 5:33:08 PM UTC-5, Mike Bayer wrote: > > On Fri, Jun 8, 2018 at 5:14 PM, HP3 > > wrote: > > Thank you so much Mike > > > > > > I am trying to write @ancestors.expression to produce a SQL like this: > > > > WITH RECURSIVE sct

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-08 Thread HP3
y follow what these queries are > returning for you, I just look very briefly to get the desired syntax > right, so a simple "here's teh code hre's the SQL" is best > > > > On Fri, Jun 8, 2018 at 2:44 PM, HP3 > > wrote: > > A!!! Makes perfect sense! >

Re: [sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-08 Thread HP3
e 8, 2018 at 12:27:28 PM UTC-5, Mike Bayer wrote: > > On Fri, Jun 8, 2018 at 12:16 PM, HP3 > > wrote: > > Attached the whole file > > OK, removing all the "zope" stuff as well as all the other queries > that aren't noted as failing, I am only look

[sqlalchemy] Re: CTE and @hybrid_property.expression

2018-06-08 Thread HP3
Attached the whole file On Thursday, June 7, 2018 at 7:01:21 PM UTC-5, HP3 wrote: > > Hello > > > Having difficulty with CTE and @hybrid_property.expression on a adjacency > list model. > > > class P2B(Base): > __tablename__ = 'p2bases' > id =

[sqlalchemy] CTE and @hybrid_property.expression

2018-06-07 Thread HP3
Hello Having difficulty with CTE and @hybrid_property.expression on a adjacency list model. class P2B(Base): __tablename__ = 'p2bases' id = Column(Integer, primary_key=True) classname = Column(String) parent_id = Column( Integer, ForeignKey('p2bases.id',

Re: [sqlalchemy] Re: Composite index using naming convention

2018-05-17 Thread HP3
> > Thanks again Mike Especially for the 63 chars length warning!!! -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See

[sqlalchemy] Re: Composite index using naming convention

2018-05-16 Thread HP3
`prop_b = Column(..., index=True)` Perhaps the convention could be defined to account for multiple columns? Could I call the naming convention explicitly? Index(Meta.naming_convention.generate_name(...), MyModel.prop_a, MyModel.prop_b) On Wednesday, May 16, 2018 at 3:42:53 PM UTC-5, HP3 wrote

[sqlalchemy] Composite index using naming convention

2018-05-16 Thread HP3
Hello: How can one create a composite Index whose name follows the naming convention declared in Meta? We are using naming convention for all ORMed classes per http://docs.sqlalchemy.org/en/latest/core/constraints.html#configuring-constraint-naming-conventions but explicit Index'es end up

Re: [sqlalchemy] Can a @hybrid_property be overriden?

2016-10-10 Thread HP3
Great! Thank you very much Mike (and also thanks for catching the error in the `UserWithBonuses` class declaration) On Saturday, October 8, 2016 at 9:02:37 AM UTC-5, Mike Bayer wrote: > > > > On 10/07/2016 05:49 PM, HP3 wrote: > > Hello all, > > > > Can a

[sqlalchemy] Can a @hybrid_property be overriden?

2016-10-07 Thread HP3
Hello all, Can a @hybrid_property be overriden by a subclass? Consider this modified example: (from http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/hybrid.html#correlated-subquery-relationship-hybrid) A subclass of User, UserWithBonuses, have its computed `balance` by adding all balances

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-26 Thread HP3
Agreed! Thank you very much again! -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-26 Thread HP3
Thank you! So, the following is all true? Recap'ing the solution (Jason's and yours combined): 1- On `after_flush`, call `history_meta.create_version()` for each object that is changing so its `XYZHistory` instance is created and can be stored within `session.info`. 2. On `before_commit`, do

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-26 Thread HP3
It seems like 0.9 does not have 'parent' in `SessionTransaction`. Instead, it has `_parent`. Would `_parent` suffice? On Monday, September 26, 2016 at 12:09:55 PM UTC-5, HP3 wrote: > > Thank you Mike, > > So basically, I should move the cleanup from > `after_commit`/

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-26 Thread HP3
Thank you Mike, So basically, I should move the cleanup from `after_commit`/`after_rollback` to `after_transaction_end` and do it **only** if `transaction.parent is None`? Recap'ing the solution (Jason's and yours combined): 1- On `after_flush`, call `history_meta.create_version()` for each

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-23 Thread HP3
I just tried cleaning up at `after_transaction_end` but the whole history stopped working. It seems like `after_transaction_create`/`after_transaction_end` surrounds the loading of a one-to-many relationship.Thus, when `after_commit` happened, the `history_objects` dict had being emptied

Re: [sqlalchemy] Re: Question about collection_class=ordering_list and Bullet.slide = slide

2016-09-23 Thread HP3
Thank you very much Mike! The behavior I am getting is very strange. The test case (I posted and then removed by accident) validates the behavior of "append to list". IOW: position is correct and not None. 105 def test_backref_set(self): 106 self._setup(ordering_list('position'))

Re: [sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-23 Thread HP3
Thank you Mike! At this point, I am cleaning session.info["history-objects"] in 'after_commit' and 'after_rollback'. I was wondering about 'after_soft_rollback` too ... (I discovered that history objects were being "re-added" when I was issuing session.rollback() so I added the cleanup there

[sqlalchemy] Re: Question about collection_class=ordering_list and Bullet.slide = slide

2016-09-23 Thread HP3
There seems to be something else ... The following test passes which indicates that position is set as 0 right after the bullet and the slide are related: 93 def test_backref_set(self): 94 self._setup(ordering_list('position')) 95 96 #session = create_session() 97

[sqlalchemy] Re: Question about collection_class=ordering_list and Bullet.slide = slide

2016-09-23 Thread HP3
> > The test below (test/ext/test_orderinglist.py) demonstrates the behavior: > 93 def test_backref_set(self): 94 self._setup(ordering_list('position', count_from=0, 95 reorder_on_append=True)) 96 97 s1 = Slide('Slide #1') 98

[sqlalchemy] Question about collection_class=ordering_list and Bullet.slide = slide

2016-09-23 Thread HP3
Hello all, In regards to ordering_list: http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/orderinglist.html from sqlalchemy.ext.orderinglist import ordering_list Base = declarative_base() class Slide(Base): __tablename__ = 'slide' id = Column(Integer, primary_key=True) name =

[sqlalchemy] examples/versioned_history/history_meta.py Coalescing changes to produce a single history insert

2016-09-23 Thread HP3
Hello all, Couple of weeks back (see [*]), while discussing that history_meta.py performs an update and an insert for each session.dirty object whenever session.flush() happens, Simon suggested the following solution to coalesce all changes within the same transaction into a single insert and

Re: [sqlalchemy] Session autoflush when using history_meta (examples/versioned_history)

2016-09-02 Thread HP3
Thank you Mike, I will strongly consider creating a PR for an alternative solution. I would need to dig into the library to learn the basics of sqlalchemy architecture though. So far, I have only used 0.9.x and few of the recipes. Recommendations for "reading/learning" material I should get

[sqlalchemy] Session autoflush when using history_meta (examples/versioned_history)

2016-09-02 Thread HP3
Hello all: We are using examples/versioned_history (i.e. history_meta.py) https://github.com/zzzeek/sqlalchemy/blob/master/examples/versioned_history/history_meta.py We noticed the following behavior: Within the same transaction (i.e. pyramid_tm), whenever a Versioned object changes and its

Re: [sqlalchemy] examples/versioned_history test_versioning.py doubts about TestVersioning.test_relationship

2016-09-02 Thread HP3
ory: > > http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#flushing > > Hope that helps, > > Simon > > On Fri, Sep 2, 2016 at 5:12 PM, HP3 <henddher...@gmail.com > > wrote: > >> Hello all: >> >> >> We are running into an issue while

[sqlalchemy] examples/versioned_history test_versioning.py doubts about TestVersioning.test_relationship

2016-09-02 Thread HP3
Hello all: We are running into an issue while using history_meta.py (examples/versioned_history). I am running test_versioning.py (via sqla_nose) but I am confused about test_relationship unit-test. It asserts sc.version == 3 without an intermediate sess.commit() ... why would the

Re: [sqlalchemy] history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint p2docs_history_pkey

2014-12-08 Thread HP3
for consideration as a formal recipe. Cheers -- Forwarded message -- From: HP3 henddher...@gmail.com javascript: Date: 5 December 2014 at 10:36 Subject: [sqlalchemy] history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint

Re: [sqlalchemy] history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint p2docs_history_pkey

2014-12-08 Thread HP3
Clarification: Originally, when we tried SELECT FOR UPDATE and isolation_level SERIALIZABLE unsuccessfully, we were using pyramid_tm 0.7. As soon as we upgraded to 0.8, it all started working correctly. On Monday, December 8, 2014 6:15:26 PM UTC-6, HP3 wrote: Thank you all, It turned out

[sqlalchemy] history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint p2docs_history_pkey

2014-12-04 Thread HP3
Hello all, We are facing a problem when using history_meta.py recipe. It seems like two concurrent transactions read the same (id,version) tuple at #1 and then each one tries to insert a new row into the pbases_history table with the same pk (id, version) combination (see #2) By removing #2,

[sqlalchemy] Re: history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint p2docs_history_pkey

2014-12-04 Thread HP3
Thank you very much Mike We just tried this: session.query(obj.__class__.version).with_for_update().filter(obj.__class__.id == obj.id).one() attr['version'] = obj.version ... But the end result was the same: IntegrityError: (IntegrityError) duplicate key value violates unique

[sqlalchemy] Re: history_meta.py IntegrityError: (IntegrityError) duplicate key value violates unique constraint p2docs_history_pkey

2014-12-04 Thread HP3
2014-12-04 19:06:16,938 INFO [root][MainThread] http://localhost:6543/resources/pages/0001---0002-0001/annotations 2014-12-04 19:06:16,938 INFO [root][MainThread] http://localhost:6543/resources/pages/0001---0002-0001/annotations 2014-12-04