Prepend type for master/detail models with a plugin app label #3801
Conversation
|
Hello @goosemania! Thanks for updating the PR.
Comment last updated on December 19, 2018 at 15:50 Hours UTC |
ce2ca3e
to
c4c3872
Compare
|
The failures are in pulp_file tests, the changes to pulp_file plugin are required. |
7ad7273
to
a1789e3
Compare
1695906
to
3ae3962
Compare
Codecov Report
@@ Coverage Diff @@
## master #3801 +/- ##
======================================
Coverage 52.9% 52.9%
======================================
Files 65 65
Lines 2805 2805
======================================
Hits 1484 1484
Misses 1321 1321
Continue to review full report at Codecov.
|
re #4185 https://pulp.plan.io/issues/4185 Required PR: pulp/pulp#3801
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.
LGTM 👍
pulpcore/app/models/base.py
Outdated
| else: | ||
| detail_model_type = self.TYPE | ||
| self.type = '{app_label}.{type}'.format(app_label=self._meta.app_label, | ||
| type=detail_model_type) |
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.
If the model is already saved, and is then modified and saved again, would this result in the app label being repeated?
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.
e.g.
if self.type:
detail_model_type = self.type
else:
detail_model_type = self.TYPE
# detail_model_type == "pulp_file.file", because it has already been saved
self.type = '{app_label}.{type}'.format(
app_label=self._meta.app_label, # pulp_file
type=detail_model_type # pulp_file.file
)
# self.type == "pulp_file.pulp_file.file"
I think that line should be underneath the "else" block instead of after it.
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.
@goosemania I don't quite understand why self.type needs to be re-set if it is already set. Would this be a correct way to do it?
if not self.type:
self.type = '{app_label}.{type}'.format(app_label=self._meta.app_label, type=self.TYPE)
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.
@dralley , I agree with your concern, thanks for pointing out. I'll update the PR.
Yeah, initially it was the way you wrote, it just means that we can't guarantee proper namespacing for types. If plugin sets a type field themselves, we are not doing anything, it can be in any format possible.
The benefit is that it's more flexible for plugin writers, though I'm not sure how critical it is for them to control the type field fully.
The downside is that we would never be able to rely on the type field to identify which plugin it came from, if we ever need to write a migration for the table related to the master 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.
I think that's an acceptable risk. The plugins shouldn't set the type field themselves unless they know what they are doing and even then they are on their own if they do so.
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.
See comments
3ae3962
to
920e1ca
Compare
920e1ca
to
adf83ff
Compare
re #4185 https://pulp.plan.io/issues/4185 Required PR: pulp/pulp#3801
closes #4185
https://pulp.plan.io/issues/4185
Required PR: pulp/pulp_file#150