Skip to content
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

Migration error when collecting context with management command #109

Closed
enoch2110 opened this issue Dec 9, 2023 · 1 comment · Fixed by #150
Closed

Migration error when collecting context with management command #109

enoch2110 opened this issue Dec 9, 2023 · 1 comment · Fixed by #150

Comments

@enoch2110
Copy link

When collecting context with management command using the example provided in the documentation, Applying pghistory.0004_auto_20220906_1625 migration fails with IndexError.

It seems all trigger relationed migrations fails with IndexError.

#!/usr/bin/env python
import contextlib
import os
import sys

import pghistory

if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
    from django.core.management import execute_from_command_line

    if len(sys.argv) > 1 and not sys.argv[1].startswith('runserver'):
        # Group history context under the same management command if
        # we aren't running a server.
        history_context = pghistory.context(command=sys.argv[1])
    else:
        history_context = contextlib.ExitStack()

    with history_context:
        execute_from_command_line(sys.argv)

Migration works fine when using default manage.py (without context collection for management command)

I tested on newly created django project and the package versions were as follows.

  • django-pghistory: v3.1.0
  • django-pgtrigger: v4.11.0
  • django: v5.0
  • psycopg2-binary: v2.9.9
  • PostgreSQL: v15.3
@wesleykendall
Copy link
Member

Thanks for letting me know! I reproduced this myself and made an issue at #149 that overviews the underlying problem.

This is likely not going to be an issue for people using context tracking in normal usage, but rather when tracking migrate, which could have all sorts of custom SQL. The 0004 migration, for example, has exactly that.

For now, I updated the docs to not include migrate in this code example. Will follow up on the actual underlying fix in a later release.

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

Successfully merging a pull request may close this issue.

2 participants