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

Test automatic wrapping of model manager #679

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

stianjensen
Copy link
Contributor

The docs say that any custom model manager will be automatically wrapped
with the money_manager (at least as long as it's named 'objects').
(https://github.com/django-money/django-money#important-note-on-model-managers)

I'm having some issue where it seems like that doesn't happen, though.
Trying to add a test case to show that it doesn't work as the
documentation explains it.

Am I misunderstanding something?

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2022

Codecov Report

Merging #679 (1144401) into main (d392e81) will not change coverage.
The diff coverage is n/a.

❗ Current head 1144401 differs from pull request most recent head 943d54b. Consider uploading reports for the commit 943d54b to get more accurate results

@@           Coverage Diff           @@
##             main     #679   +/-   ##
=======================================
  Coverage   97.08%   97.08%           
=======================================
  Files          29       29           
  Lines         961      961           
  Branches      186      186           
=======================================
  Hits          933      933           
  Misses         21       21           
  Partials        7        7           

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 d392e81...943d54b. Read the comment docs.

@stianjensen
Copy link
Contributor Author

Huh – When I ran this test locally, it failed:

==================================================================================== FAILURES =====================================================================================
_________________________________________________________________ test_automatic_wrapping_of_custom_model_manager _________________________________________________________________

    def test_automatic_wrapping_of_custom_model_manager():
        manager_class = ModelWithCustomManagerWithoutExplicitWrapping.objects.__class__
>       assert manager_class.__module__ + "." + manager_class.__name__ == "djmoney.models.managers.MoneyManager"
E       AssertionError: assert 'tests.testap...mMoneyManager' == 'djmoney.mode....MoneyManager'
E         - djmoney.models.managers.MoneyManager
E         + tests.testapp.models.CustomMoneyManager

The docs say that any custom model manager will be automatically wrapped
with the money_manager (at least as long as it's named 'objects').
(https://github.com/django-money/django-money#important-note-on-model-managers)

I'm having some issue where it seems like that doesn't happen, though.
Trying to add a test case to show that it doesn't work as the
documentation explains it.

Am I misunderstanding something?
@stianjensen
Copy link
Contributor Author

Huh – When I ran this test locally, it failed:

So it turns out the test passes if you run the whole test suite, but fails when running the test individually. I guess something stateful is kept between the tests which causes the behavior to change.

Adding this seems to also make the test pass when I run it alone, and
seems to work better on my codebase. Need to dig deeper into Django to
figure out exactly why.
@benjaoming
Copy link
Contributor

@stianjensen could you try to merge in the latest main? 🙏

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.

None yet

3 participants