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
Most recent with excluded fields #477
Most recent with excluded fields #477
Conversation
simple_history/models.py
Outdated
@@ -65,6 +65,9 @@ def __init__(self, verbose_name=None, bases=(models.Model,), | |||
except TypeError: | |||
raise TypeError("The `bases` option must be a list or a tuple.") | |||
|
|||
def _get_excluded_fields(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used? Can't see it being called anywhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not being used anywhere. My mistake since I hadn't spot the meta attribute containing the excluded fields in the first place.
self.assertIn('question', all_fields_names) | ||
self.assertNotIn('pub_date', all_fields_names) | ||
self.assertEqual(most_recent.__class__, PollWithExcludeFields) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we also get a test case that ensures that the excluded fields are indeed excluded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kseever the test here is already checking whether the field is present in the fields of the history model so I think it's already being covered. I have added another statement checking if the field is present in the excluded fields of the history model. It might be that I may have failed to understand your requirement so please feel free to elaborate. =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I just noticed that the assertion I was looking for already exists on line 403 - confirming that pub_date
isn't in the list of returned fields. Nevermind me!
@Alig1493 not sure why this isn't building. Want to try fixing conflicts and pushing? |
I'll have the conflicts resolved. SOrry for the delayed response |
b71b1fb
to
4f78744
Compare
Want to run |
@rossmechanic sure I'll do it right away. sorry for the late reply. |
Codecov Report
@@ Coverage Diff @@
## master #477 +/- ##
=========================================
+ Coverage 97.23% 97.74% +0.5%
=========================================
Files 16 17 +1
Lines 724 799 +75
Branches 95 111 +16
=========================================
+ Hits 704 781 +77
+ Misses 10 8 -2
Partials 10 10
Continue to review full report at Codecov.
|
@rossmechanic any advice regarding solving cyclomatic complexity |
@Alig1493 refactoring your new code into a |
@rossmechanic Is my latest change what you had in mind? Maybe I missed something? |
@Alig1493 yes! just rebase and the codeclimate issue should go away. However, I would like to see the code coverage increase |
I'll have it rebased soon. Sorry was on leave. |
…ching most recent. Updated test_model_with_excluded_fields test to verify.
61c8ab3
to
e28710a
Compare
@rossmechanic I have rebased and pushed but it seems the initial problem still persists. Anything I might have missed? |
simple_history/manager.py
Outdated
@@ -34,6 +34,11 @@ def get_queryset(self): | |||
key_name = self.instance._meta.pk.name | |||
return self.get_super_queryset().filter(**{key_name: self.instance.pk}) | |||
|
|||
def get_excluded_fields(self): | |||
if isinstance(self.instance._meta.model.history, self.__class__): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't want to hardcode history
here. Instead, use utils.get_history_manager_for_model
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this conditional checking for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using this conditional check because I thought all the instances might not have a model history class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should all have a model history class. However, they might not have _history_excluded_fields
so you should do:
excluded_fields = getattr(self.model, '_history_excluded_fields', [])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh shoot you're right. Now that I'm looking at the print statements for debugging it's painfully obvious. Damn!
simple_history/manager.py
Outdated
@@ -34,6 +34,11 @@ def get_queryset(self): | |||
key_name = self.instance._meta.pk.name | |||
return self.get_super_queryset().filter(**{key_name: self.instance.pk}) | |||
|
|||
def get_excluded_fields(self): | |||
if isinstance(self.instance._meta.model.history, self.__class__): | |||
return self.instance._meta.model.history.model._history_excluded_fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could do self.model._history_excluded_fields
@Alig1493 don't worry about the codeclimate error, but I left a few other comments. Also want to get the codecov/patch up to 100% |
@rossmechanic the codecov patch is upto a 100% just like you mentioned. |
@Alig1493 Great! Just left one more comment |
@rossmechanic I've made your requested changes. |
simple_history/manager.py
Outdated
tmp.append(field.name + "_id") | ||
elif field.name not in excluded_fields: | ||
tmp.append(field.name) | ||
if field.name not in excluded_fields: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might just change this so you don't nest the if
statement.
Try:
if field.name in excluded_fields:
continue
elif isinstance(field, models.ForeignKey):
tmp.append(field.name + "_id")
else:
tmp.append(field.name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you made the changes? If not maybe I can just do them and push it for you and it stays there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea can you do that? Then I’ll merge
@rossmechanic please see if the changes are in order. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Thanks!
Description
Added changes in manager to compensate for excluded fields while feetching most recent. Updated test_model_with_excluded_fields test to verify.
Related Issue
Steps to reproduce:
most_recent cannot be combined with excluded_fields #333
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: