fix: handle pre-begun transactions and custom PK column names #5
No reviewers
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
CobraPack/repository!5
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/session-transaction-and-pk-lookup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Two bugs causing 500 errors in print-estimate-api E2E tests:
Bug 1: Session transaction conflict
InvalidRequestError: A transaction is already begun on this Session.create/update/removerepos callsession.begin(), but when the session factory already starts a transaction (e.g.sessionmaker.begin()pattern used in peapi), this raises an error.async_transaction()/sync_transaction()helpers that checksession.in_transaction()and usebegin_nested()(savepoint) when a transaction is already active.Bug 2: Primary key attribute lookup
AttributeError: material_profile_idget_primary_key()returned SQL column names instead of Python attribute names. When models useid: PrimaryKeyType = PrimaryKey("material_profile_id"), the column name != attribute name.sa_inspect) to resolve column name → Python attribute name mapping.Test plan
TestAsyncPreBegunTransaction(4 tests),TestSyncPreBegunTransaction(2 tests),test_custom_column_name_returns_attribute_name(1 test)Version bumped to 1.8.2.
Two bugs fixed: 1. Session transaction conflict: When the session factory already starts a transaction (e.g. `sessionmaker.begin()`), the repo's internal `session.begin()` raised `InvalidRequestError: A transaction is already begun`. Fix: use `begin_nested()` (savepoint) when a transaction is already active. Affects create, update, and remove in both async and sync repos. 2. Primary key attribute lookup: `get_primary_key()` returned SQL column names (e.g. `material_profile_id`) instead of Python attribute names (e.g. `id`). This caused `AttributeError` in `get_entity()` and `remove()` when models use custom PK column names via `sa_column=Column("custom_name", ...)`. Fix: use SQLAlchemy mapper inspection to resolve column→attribute mapping. Bump version to 1.8.2. Co-Authored-By: Paperclip <noreply@paperclip.ing>