Skip to content

New feature --lazy-db: --reuse-db with --create-db on DB error / ProgrammingError #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
blueyed opened this issue Feb 26, 2015 · 3 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Feb 26, 2015

What do you think about a new option --lazy-db, which would behave like --reuse-db, but falls back to --create-db when there's a DB error during the first test.

Would that be possible / feasible?
Could this be done by default, without a new option?

For example:

    def execute(self, sql, params=None):
        self.db.validate_no_broken_transaction()
        self.db.set_dirty()
        with self.db.wrap_database_errors:
            if params is None:
                return self.cursor.execute(sql)
            else:
>               return self.cursor.execute(sql, params)
E               ProgrammingError: relation "languages_plus_language" does not exist
E               LINE 1: ...."family", "languages_plus_language"."notes" FROM "languages...
E                                                                            ^

…/django-1.7.x/django/db/backends/utils.py:65: ProgrammingError
@pelme
Copy link
Member

pelme commented Mar 29, 2015

What would the outcome of that test be after the exception? Should db recreation happen and then the test be re-run? That would be a bit magic, but might be useful.

I see these kinds of errors when there are schema changes and I forgot to run with --create-db. Could we use migrations to migrate the test database to the correct state automatically, instead of re-running migrations from scratch?

@pelme
Copy link
Member

pelme commented Mar 29, 2015

(#220 is about running migrations with --reuse-db to make sure the database is up to date)

@jedie
Copy link

jedie commented Nov 17, 2016

Is it possible to detect if there are new schema changes and then force "--create-db" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants