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

fix: clear delayed apps cache of migrations project state #294

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

skarzi
Copy link
Collaborator

@skarzi skarzi commented Jun 9, 2022

I am still thinking about the test (how to write the simplest and minimal version of it), so this PR is a draft, but feel free to write some suggestions in the comments.

Closes #292

@skarzi skarzi self-assigned this Jun 9, 2022
@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #294 (670f45e) into master (35bad71) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #294   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          328       330    +2     
  Branches        46        46           
=========================================
+ Hits           328       330    +2     
Impacted Files Coverage Δ
django_test_migrations/migrator.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 35bad71...670f45e. Read the comment docs.

@sobolevn
Copy link
Member

@skarzi
Copy link
Collaborator Author

skarzi commented Jun 13, 2022

It's useful, but for some reason test from test_bad.py from this ZIP file is always passing.
I just extracted a new migration 0006 for the following model:

class ModelWithItem(models.Model):
    """We use this model for testing migrations."""

    some_item = models.ForeignKey(
        'main_app.SomeItem',
        on_delete=models.PROTECT,
    )

and the following test:

@pytest.mark.django_db()
def test_pytest_plugin0006(migrator):
    """Ensure apps cache is delayed."""
    state = migrator.apply_initial_migration(
        ('main_app', '0006_modelwithitem'),
    )

    SomeItem = state.apps.get_model('main_app', 'SomeItem')
    ModelWithItem = state.apps.get_model('main_app', 'ModelWithItem')
    some_item = SomeItem.objects.create(string_field='test', is_clean=True)

    assert ModelWithItem.objects.create(some_item=some_item)

from the ZIP file.

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 this pull request may close these issues.

Models from app state aren't compatible (Cannot assign "<A: A object (1)>": "B.a_fk" must be a "A" instance)
2 participants