Skip to content

Allow filter model to be a subclass of the queryset one. #1398

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

Closed
wants to merge 1 commit into from

Conversation

charettes
Copy link
Contributor

The original issubclass check seems to have been misused.

Also moved the FilterableItem model to the common module since the one defined in test_filters was actually a reference to the one defined in test_pagination because of the way BaseModel.__new__ works.

decimal = models.DecimalField(max_digits=4, decimal_places=2)
date = models.DateField()


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to move into models? We should try to keep models close to their corresponding test cases where possible. (Even if it means redefining in some places)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both models are defined in the tests package they both have the same app_label ('tests').

Because the test_pagination module was loaded before the test_pagination one and Django cache model definition by (app_label, model_name) to work around double imports test_filters.FilterableItem was actually test_pagination.FilterableItem. You can verify this by printing test_filters.FilterableItem.__module__.

I hit this issue while attempting to define a base of FilterableItem to add the test cases for this bugfix by attempting to define BaseFilterableItem in test_filters and realizing FilterableItem was not a subclass of it due to the Django model definition cache behavior described above.

Since both the test_filters and the test_pagination model had the same definition I thought moving them to the models module would be a great way to solve this issue.

I don't mind keeping models separate if you prefer. We'll just have to rename test_pagination.FilterableItem to another name.

@xordoquy
Copy link
Collaborator

@tomchristie what's the reason you try to keep models inside the tests ?

@tomchristie
Copy link
Member

what's the reason you try to keep models inside the tests ?

  • It's not clear when they can be deleted otherwise.
  • Models end up getting reused between differing tests, pull requests then add in extra fields, options etc and otherwise making the tests less focused.
  • The tests should be as self-contained as possible.

@charettes
Copy link
Contributor Author

@tomchristie in this case do you want me to rename one of two conflicting models?

@xordoquy
Copy link
Collaborator

@charettes I'll most probably update this PR to go against 2.4.x branch which moved the test location. I'll deal with the model change by then.

@tomchristie
Copy link
Member

What's the status on this? Just waiting for updating against latest master?

@tomchristie tomchristie added this to the 2.4 Release milestone Aug 18, 2014
@xordoquy
Copy link
Collaborator

@tomchristie due to 1.7 support, the FilterableItem has been moved into the models application. This is because does not validate two models with the same name / application.
IMO this is sensible but if you'd rather have models in their test files we can move them back and rename them to avoid name collision. I opened #1777 to discuss further on the matter.

xordoquy added a commit to linovia/django-rest-framework that referenced this pull request Aug 19, 2014
@xordoquy xordoquy mentioned this pull request Aug 19, 2014
@xordoquy
Copy link
Collaborator

Closing this PR in favor of #1778 (same PR against 2.4 branch)

@xordoquy xordoquy closed this Aug 19, 2014
@xordoquy
Copy link
Collaborator

Thanks for the PR and sorry it took so long

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

Successfully merging this pull request may close these issues.

3 participants