I am working with sqlalchemy-continuum to use versioning on selected database tables in a flask app with mssql. In my end-to-end tests I run a flask app context that populates flask's global g object with user information that sqlalchemy-continuum handles via its UserPlugin. The problem is I want to load an exact database state from hand-written json files (using the flask-fixtures library) and I need full control of what is in the database for this. Since sqlalchemy-continuum is auto-populating the transactions table when my json contains data for the versioned tables I am unable to control the user information that is being stored in the transactions table. I want to be able to do something like this in the course of loading the db state from my json 'fixture' file:
# establish if a transaction table is provided in the json state (by me)
if fixture["model"] == "transaction":
special_transaction = fixture
...
# code for loading db state for all 'normal' tables then later:
if special_transaction is not None:
statement = text(
"insert into [transaction] "
"(issued_at, remote_addr, user_id) "
"values (:remote_addr, :issued_at, :user_id)"
)
session = <the code that gets my session>
for record in fixture["records"]:
session.execute(statement, record)
session.commit()
This currently does not work because sqlalchemy-continuum has already 'magically' populated the transaction table by this point so I get clashes trying to add my custom data to it. How can I switch off that behaviour to give me full control of my database state in the test run?