Skip to content

Scoped SQLAlchemy event publishing emits transaction deassociated warning #7

@jose-matos-9281

Description

@jose-matos-9281

Problem

Using python-hexagonal 0.3.0 scoped runtime with SQLAlchemy emits SAWarning: transaction already deassociated from connection on the integration-event publish path.

Reproduction context

Consumer repo: inteligencia-pdss-contactos
Path exercised through real app bootstrap and event publishing.

Focused pytest runs that reproduce it:

  • uv run pytest src/tests/use_cases/test_scoped_runtime.py -q -W always
  • uv run pytest src/tests/use_cases/contacto/test_marcar_contactado.py -q -W always

Observed stack direction

The warning appears during upstream outbox/message-bus handling:

  • BaseAPI.publish_and_wait()
  • MessageBus.publish_from_outbox()
  • SQLAlchemyOutboxRepository.mark_as_published()
  • SQLAlchemyConnectionContextManager.cursor() commit/transaction handling

Why this matters

The migration works functionally, but the warning suggests a transaction-boundary problem in nested or re-entrant outbox publishing. Even if it does not fail today, it is noisy and may hide a real edge case.

Request

Please review the SQLAlchemy outbox publish flow in scoped execution mode and ensure mark_as_published() / connection context handling does not commit against a transaction that has already been deassociated.

If useful, I can provide a minimized repro extracted from the consumer app path.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions