Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

stephenfin/alembic-sqlite-memory-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demonstration of a possible oslo.db-alembic bug

Resolution This wasn't an issue with oslo.db. Instead, we were creating multiple connections as part of our migration. This doesn't work with in-memory databases. The final commit in this repo contains the fixes. You can view the comments from @zzzeek suggesting the fix here.

There seems to be a weird interaction between oslo.db and alembic. This demonstrates this. You can validate this with pytest (unittest would also work). First, create a virtualenv:

$ virtualenv .venv
$ . .venv

Then install the dependencies before running tests:

(venv) $ pip install -r requirements.txt
(venv) $ pytest

You'll see the test fails and prints the following:

Expected:
['alembic_version', 'volume_usage_cache']

Actual:
[]

However, if I run alembic upgrade head using the provided alembic.ini then we see:

Expected:
['alembic_version', 'volume_usage_cache']

Actual:
['alembic_version', 'volume_usage_cache']

We can achieve the same thing using an in-memory database. If we make the following change:

diff --git alembic.ini alembic.ini
index 00ee926..fb196bc 100644
--- alembic.ini
+++ alembic.ini
@@ -8,7 +8,7 @@ script_location = %(here)s/foo/migrations
 # defaults to the current working directory.
 prepend_sys_path = .
 
-sqlalchemy.url = sqlite:///foo.db
+sqlalchemy.url = sqlite://
 
 # Logging configuration
 [loggers]

Then we also get the following output from alembic upgrade head:

Expected:
['alembic_version', 'volume_usage_cache']

Actual:
[]

So this seems to be an issue with context changing and a new in-memory database being created.

About

A demo of issues using SQLA reflection and in-memory databases

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published