Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ilanKeshet
Copy link

Following discussion #11243

Description

  1. Exposing private attribute SessionTransaction._rollback_exception using public property rollback_exception
  2. In TransactionalContext._trans_ctx_check() when a closed transaction is detected. first checking a transaction's rollback_exception is accessible and if it is, raising an InvalidRequestError which includes it in the error message

Checklist

This pull request is:

  • A documentation / typographical / small typing error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

trans_context = subject._trans_context_manager
if trans_context:
if not trans_context._transaction_is_active():
transaction = getattr(subject, "transaction", None)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzzeek is using getattr in this context acceptable, or would you prefer that the _TConsSubject protocol be extended to also require subjects passed to _trans_ctx_check have a transaction attribute?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the protocol should be expanded and I would stick to underscored names in all cases

@ilanKeshet ilanKeshet marked this pull request as ready for review April 23, 2024 13:05
return self.nested or not self._parent

@property
def rollback_exception(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep this underscore, dont want to add more public accessors, note TransactionalContext uses underscored method names as its API

trans_context = subject._trans_context_manager
if trans_context:
if not trans_context._transaction_is_active():
transaction = getattr(subject, "transaction", None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the protocol should be expanded and I would stick to underscored names in all cases

if trans_context:
if not trans_context._transaction_is_active():
transaction = getattr(subject, "transaction", None)
if transaction is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collapse these two if statements

transaction = getattr(subject, "transaction", None)
if transaction is not None:
if transaction.rollback_exception is not None:
raise exc.InvalidRequestError(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two raises that look identical should be just the one raise

@zzzeek
Copy link
Member

zzzeek commented May 18, 2024

there's changes requested on this PR if you're still around

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants