From: Mike Bayer Date: Wed, 26 May 2021 16:13:30 +0000 (-0400) Subject: remove outdated integrityerror example X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2b0b35bc75bfe2f4e66887e0dd3038a69ee41adf;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git remove outdated integrityerror example Fixes: #5372 Change-Id: Ibf7c9969be543e38cd0c4773c413f085a57d94ab (cherry picked from commit 4befa30bdb155e03808968f8fc6b32f39976177d) --- diff --git a/doc/build/orm/session_state_management.rst b/doc/build/orm/session_state_management.rst index 40e50cda15..632bb667b2 100644 --- a/doc/build/orm/session_state_management.rst +++ b/doc/build/orm/session_state_management.rst @@ -349,27 +349,15 @@ Further detail on cascade operation is at :ref:`unitofwork_cascades`. Another example of unexpected state:: >>> a1 = Address(id=existing_a1.id, user_id=u1.id) - >>> assert a1.user is None - True + >>> a1.user = None >>> a1 = session.merge(a1) >>> session.commit() sqlalchemy.exc.IntegrityError: (IntegrityError) address.user_id may not be NULL -Here, we accessed a1.user, which returned its default value -of ``None``, which as a result of this access, has been placed in the ``__dict__`` of -our object ``a1``. Normally, this operation creates no change event, -so the ``user_id`` attribute takes precedence during a -flush. But when we merge the ``Address`` object into the session, the operation -is equivalent to:: - - >>> existing_a1.id = existing_a1.id - >>> existing_a1.user_id = u1.id - >>> existing_a1.user = None - -Where above, both ``user_id`` and ``user`` are assigned to, and change events -are emitted for both. The ``user`` association -takes precedence, and None is applied to ``user_id``, causing a failure. +Above, the assignment of ``user`` takes precedence over the foreign key +assignment of ``user_id``, with the end result that ``None`` is applied +to ``user_id``, causing a failure. Most :meth:`~.Session.merge` issues can be examined by first checking - is the object prematurely in the session ?