DatabaseResource.make() sends creation to a non-global facade

Bug #1806137 reported by Mike Bayer
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.db
Triaged
Medium
Mike Bayer

Bug Description

Trying to actually use a GeneratesSchema facade with a project that has its own TransactionContextManager, which is now the standard approach. more research is needed here but when provision.DatabaseResource.make() generates a new TCM, that's not the one which the calling application knows about. schema is created on the wrong engine and the whole thing fails. this is of course local to the SQLite case where we are using in-memory DBs, for a server/file DB the two facades would talk to the same URL. But the design here doesn't work, it seems like it should be replacing the factory inside the TCM but leaving the TCM in place. Short attempts to make this happen didn't work so this needs some more effort. Also need to re-understand how this works at all since I'm not following how the existing test in test_fixtures.py works, it might be dependent on the fact that this is the global manager.

Mike Bayer (zzzeek)
Changed in oslo.db:
assignee: nobody → Mike Bayer (zzzeek)
Revision history for this message
Mike Bayer (zzzeek) wrote :

OK, research has been done. The problem is that hooks like GeneratesSchema.generate_schema_create_all are called before we apply the ReplaceEngineFacadeFixture to patch the local enginefacade into the one given to us by the application. Since it's common that tests want to use their normal enginefacade-enabled application code to set up test data, this causes things to not work. As a workaround, a fixture can do this:

    def generate_schema_create_all(self, engine):
        migration.create_schema(engine)

        _reset_facade = myapp.context_manager.patch_engine(
            engine)
        self.addCleanup(_reset_facade)

        # do enginefacade-specific setup

this is what I've done in placement for now.

Revision history for this message
Ben Nemec (bnemec) wrote :

So do we need to add a test fixture for this?

Revision history for this message
Mike Bayer (zzzeek) wrote :

We will, yes. I was planning to work on it at some point. for the review where I had the problem see https://review.openstack.org/#/c/621304/.

Ben Nemec (bnemec)
Changed in oslo.db:
status: New → Triaged
importance: Undecided → Medium
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.