Having migrated most of our code across to pants, ...
# general
a
Having migrated most of our code across to pants, I'm now tackling the beast: Django. I'm struggling to get pytest-django to work, because it's failing while running migrations
Copy code
elf = <django.db.backends.utils.CursorWrapper object at 0x7f1f6d967970>
sql = 'ALTER TABLE "dz_user_groups" ADD CONSTRAINT "dz_user_groups_group_id_2e149f2f_fk_auth_group_id" FOREIGN KEY ("group_id") REFERENCES "auth_group" ("id") DEFERRABLE INITIALLY DEFERRED'
params = ()
ignored_wrapper_args = (False, {'connection': <django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f1f6f5bce20>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x7f1f6d967970>})

    def _execute(self, sql, params, *ignored_wrapper_args):
        self.db.validate_no_broken_transaction()
        with self.db.wrap_database_errors:
            if params is None:
                # params default might be backend specific.
                return self.cursor.execute(sql)
            else:
>               return self.cursor.execute(sql, params)
E               django.db.utils.ProgrammingError: relation "auth_group" does not exist
My guess is that the migrations for
django.contrib.auth
aren't running before it tries to apply our custom schema. If I run
pants run .../manage.py -- migrate
then all migrations are applied. I've got
string_imports
enabled, and have got the PANTS_EXECUTION_SLOT trick set up in a conftest. Pytest is creating a new DB per slot, and seems to be finding my migrations, but not applying auth, though it's sort of hard to tell in the absence of useful logs (thanks, django) Edit: fixed, thanks for 🦆
Pretty sure this is because migrations were't being counted as dependencies.
b
We have a Django plugin for pants, if there's room from improvement let us know. CC @happy-kitchen-89482
a
Yep, that did it. Just ran my first test. 🎉
I'll check the plugin out. I
'm gonna need all the help I can get
h
The plugin is very early days, all it does right now is infer migration deps
We have some best practices around Django, that you can see demonstrated in https://github.com/pantsbuild/example-django
We want to turn more of those practices into plugin features though
So feedback (and PRs!) are good
a
Yeah, the example is great, but it's not super helpful if you already have a big old mess of Django. Last time I did this I gave up a couple of days in, this time it took me a couple of hours. I think it's just a question of experience.
If I get time I'll write up how we went about it. I'm just setting up gunicorn and docker atm, but the app is working locally, so that's a win.
🔥 1