Unable to access records created in sub-transaction

I am trying to create a flask-tryton route that uses a read/write sub-transaction in processing a GET request (where GETs are readonly in flask-tryton).[1] The sub-transaction creates a record, but when that sub-transaction exits and workflow returns to the initial transaction, the record doesn’t appear to exist, although the record is persisted to the database.

The code is essentially:

CognitoRecord = Pool().get('cognito_record')
with Transaction().new_transaction(readonly=False) as txn:
CognitoRecord.search([])  # returns []

Despite the search returning [], the record does exist in the database, and can be viewed in the GTK.

Is this the expected behavior? Is there a pattern I should consider here?

Thanks, in advance, for your insight!

[1] The use case is an integration with AWS Cognito, where authentication confirmation is retrieved and stored during the GET.

FYI, I have it working now by starting another new_transaction(readonly=True) and running the rest of the GET request within it.

Yes because we use repeatable isolation level. So transaction can see only the data as they were when the transaction started.

Use a single transaction and make the GET not readony by passing readonly=False to the transaction decorator.

Indeed a transaction started after the sub-transaction committed will see the data committed in this one.

1 Like