3YOURMIND / django-migration-linter

:rocket: Detect backward incompatible migrations for your django project
https://pypi.python.org/pypi/django-migration-linter/
Apache License 2.0
526 stars 57 forks source link

App 'django_celery_monitor' does not have migrations #44

Closed sobolevn closed 5 years ago

sobolevn commented 5 years ago

Linting process fails with an exception when using django_celery_monitor. I expect it just to ignore apps without migrations.

Traceback:

(django_celery_monitor, 0001_initial)... Traceback (most recent call last):
  File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/bin/django-migration-linter", line 11, in <module>
    sys.exit(_main())
  File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 341, in _main
    linter.lint_all_migrations(git_commit_id=args.commit_id)
  File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 145, in lint_all_migrations
    self.lint_migration(m)
  File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 104, in lint_migration
    sql_statements = self.get_sql(app_name, migration_name)
  File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 193, in get_sql
    "sqlmigrate command failed {0}".format(err.decode("utf-8"))
RuntimeError: sqlmigrate command failed CommandError: App 'django_celery_monitor' does not have migrations

Version: django-celery-monitor==1.1.2

Usage:

INSTALLED_APPS: Tuple[str, ...] = (
    # Default django apps:
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # django-admin:
    'django.contrib.admin',
    'django.contrib.admindocs',

    # Celery:
    'django_celery_monitor',

    ...
)

Related: https://github.com/wemake-services/wemake-django-template/issues/634

David-Wobrock commented 5 years ago

Hi @sobolevn , weird I didn't manage to reproduce. Could you give more precise steps or env info please?

sobolevn commented 5 years ago

So, I had the time to make you a repo to reproduce this issue: https://github.com/sobolevn/django_migration_linter_issue_44

Documentation for the similar projects: https://wemake-django-template.readthedocs.io/en/latest/

Steps:

  1. git clone https://github.com/sobolevn/django_migration_linter_issue_44.git
  2. cd django_migration_linter_issue_44
  3. docker-compose run --rm web django-migration-linter .

The repository contains only two commits:

  1. Initial commit after crating new wemake-django-template project
  2. Adding django_migration_linter and django_celery_monitor

Output:

(axes, 0001_initial)... OK
(axes, 0002_auto_20151217_2044)... OK
(axes, 0003_auto_20160322_0929)... OK
(axes, 0004_auto_20181024_1538)... OK
(axes, 0005_remove_accessattempt_trusted)... ERR
        DROPPING columns
(django_celery_monitor, 0001_initial)... Traceback (most recent call last):
  File "/usr/local/bin/django-migration-linter", line 11, in <module>
    sys.exit(_main())
  File "/usr/local/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 341, in _main
    linter.lint_all_migrations(git_commit_id=args.commit_id)
  File "/usr/local/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 145, in lint_all_migrations
    self.lint_migration(m)
  File "/usr/local/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 104, in lint_migration
    sql_statements = self.get_sql(app_name, migration_name)
  File "/usr/local/lib/python3.6/site-packages/django_migration_linter/migration_linter.py", line 193, in get_sql
    "sqlmigrate command failed {0}".format(err.decode("utf-8"))
RuntimeError: sqlmigrate command failed CommandError: App 'django_celery_monitor' does not have migrations
David-Wobrock commented 5 years ago

Thanks a lot @sobolevn for the environment, finally got the time to work on it.

However, I still cannot reproduce.

When I clone your repo, and run the docker-compose line you are suggesting, it works. For the details, in the installation, the latest version of the linter is installed - Installing django-migration-linter (0.1.2) and on execution of it:

*** Summary:
Valid migrations: 0/0 - erroneous migrations: 0/0 - ignored migrations: 0/0

Can it be that an older version of the linter is installed in your container?

sobolevn commented 5 years ago

Nope, I am also using 0.1.2. You can see this line in lock file: https://github.com/sobolevn/django_migration_linter_issue_44/blob/master/poetry.lock#L317

What can be the case? We have docker, reproducible builds, etc. And it still does not work! 😄

David-Wobrock commented 5 years ago

Hmm, can you try cloning the repo from scratch and you give me the exact steps you do. And then the output of the docker-compose run --rm web django-migration-linter . command please

sobolevn commented 5 years ago
  1. git clone https://github.com/sobolevn/django_migration_linter_issue_44.git
  2. cd django_migration_linter_issue_44
  3. cp config/.env.template config/.env
  4. docker-compose run --rm web django-migration-linter .

Output:

Starting django_migration_linter_issue_44_db_1 ... done
wait-for-command.sh finished successfully after 1 second(s).
cmd:                 curl db:5432
target exit status:  0 52
exited status:       52
Postgres is up - continuing...
*** Summary:
Valid migrations: 0/0 - erroneous migrations: 0/0 - ignored migrations: 0/0

And it now works for me. I do not know what happened. Anyway, thanks for your time, effort, and this project!

David-Wobrock commented 5 years ago

Okay, thanks! Don't hesitate to re-open this issue if the error occurs again :)