Remove catching of AttributeError in DescriptorWrapper#624
Merged
foarsitter merged 2 commits intojazzband:masterfrom Jun 13, 2024
Merged
Remove catching of AttributeError in DescriptorWrapper#624foarsitter merged 2 commits intojazzband:masterfrom
AttributeError in DescriptorWrapper#624foarsitter merged 2 commits intojazzband:masterfrom
Conversation
There used to be a [bug in Django](https://code.djangoproject.com/ticket/30427) that caused these tests to fail, according to the discussion of jazzband#370. That bug was fixed in Django 4.0. However, because the test model was using a `FieldTracker` rather than a `ModelTracker`, all model-specific test cases in `ModelTrackerTests` continued to fail.
This catch was introduced in jazzband#367, but subsequent discussion in jazzband#370, jazzband#381 and jazzband#382 suggests that it wasn't the proper solution. Now that `AbstractModelTrackerTests` is re-enabled and passing, it becomes clear that `AttributeError` is no longer raised during unit testing when using a recent Django version. Therefore I think it is safe to remove the `try`/`except`.
Merged
Contributor
|
Underlines how valuable typing can be! Thanks for your thorough investigation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I was cleaning up the type annotations in
DescriptorWrapper.__get__():After being puzzled by the code for some time, I realized that the
value = self.descriptorstatement was inherently incompatible with the return type of the method. Also storing the descriptor rather than a value intracker_instance.saved_dataseems unlikely to be correct.Solution
I tried to find out when this exception handler runs, but it turned out it is never executed during unit testing.
Digging deeper, I found that
AbstractModelTrackerTestswas supposed to cover this code, but that test suite was marked asskipbecause it had known test failures. Re-enabling it indeed led to 4 failing test cases, all fromModelTrackerTests. The reason for that was simple though: the test modelTrackedAbstractused aFieldTrackerrather than aModelTracker. After fixing that, the test suite passed.There used to be a bug in Django that caused these tests to fail, according to the discussion of #370. That bug was fixed in Django 4.0.
This exception handler was introduced in #367, but subsequent discussion in #370, #381 and #382 suggests that it wasn't the proper solution. As we now have a working test and that test doesn't cause
AttributeErrorto be raised, I think it is safe to remove thetry/except.Commandments
CHANGES.rstfile to describe the changes, and quote according issue withGH-<issue_number>.This change should be invisible to end users, as it removes dead code. So I think the ChangeLog and docs steps can be skipped, but if you disagree, let me know and I'll update the PR.