Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Prepend type for master/detail models with a plugin app label #3801

Merged
merged 1 commit into from Dec 20, 2018

Conversation

goosemania
Copy link
Member

@goosemania goosemania commented Dec 14, 2018

@pep8speaks
Copy link

pep8speaks commented Dec 14, 2018

Hello @goosemania! Thanks for updating the PR.

Comment last updated on December 19, 2018 at 15:50 Hours UTC

@goosemania
Copy link
Member Author

The failures are in pulp_file tests, the changes to pulp_file plugin are required.

@goosemania goosemania force-pushed the issue4185 branch 3 times, most recently from 7ad7273 to a1789e3 Compare December 19, 2018 15:51
@goosemania goosemania changed the title Namespace plugins in content endpoints and in content summary report Prepend type for master/detail models with a plugin app label Dec 19, 2018
@goosemania goosemania force-pushed the issue4185 branch 2 times, most recently from 1695906 to 3ae3962 Compare December 19, 2018 16:40
@codecov
Copy link

codecov bot commented Dec 19, 2018

Codecov Report

Merging #3801 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #3801   +/-   ##
======================================
  Coverage    52.9%   52.9%           
======================================
  Files          65      65           
  Lines        2805    2805           
======================================
  Hits         1484    1484           
  Misses       1321    1321
Impacted Files Coverage Δ
pulpcore/app/models/base.py 57.69% <0%> (ø) ⬆️

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 cf30f2e...adf83ff. Read the comment docs.

goosemania added a commit to goosemania/pulp_file that referenced this pull request Dec 19, 2018
Copy link
Contributor

@daviddavis daviddavis left a comment

Choose a reason for hiding this comment

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

LGTM 👍

else:
detail_model_type = self.TYPE
self.type = '{app_label}.{type}'.format(app_label=self._meta.app_label,
type=detail_model_type)
Copy link
Contributor

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?

Copy link
Contributor

@dralley dralley Dec 19, 2018

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.

Copy link
Contributor

@dralley dralley Dec 19, 2018

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)

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@dralley dralley left a comment

Choose a reason for hiding this comment

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

See comments

@goosemania goosemania merged commit caaa00d into pulp:master Dec 20, 2018
@daviddavis daviddavis added the 3.0 label Dec 20, 2018
daviddavis pushed a commit to daviddavis/pulp_file that referenced this pull request May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants