Project

Profile

Help

Refactor #4206

Prepend all pulpcore model fields in the Content model hierarchy with _ (e.g. '_type', '_id', '_notes')

Added by dalley about 3 years ago. Updated almost 2 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
% Done:

0%

Estimated time:
Platform Release:
Groomed:
Yes
Sprint Candidate:
Yes
Tags:
Sprint:
Sprint 47
Quarter:

Description

Motivations

1. Avoiding attribute naming collisions when content writer's subclass Content.

2. Allow users to easily see which attributes are from pulpcore and therefore common to all content types.

It was determined after long discussion here [0] that the solution to this should be to make sure all of the fields used by Pulpcore on models that are intended to be extended via the Plugin API are prepended with an underscore character.

Changes

Rename the Model fields here in the following ways:
https://github.com/pulp/pulp/blob/d1dc089890f167617fe9917af087d5587708296b/pulpcore/pulpcore/app/models/base.py#L25-L27

created -> _created
id -> _id
last_updated -> _last_updated

As well as the MasterModel "type" field here:
https://github.com/pulp/pulp/blob/d1dc089890f167617fe9917af087d5587708296b/pulpcore/pulpcore/app/models/base.py#L80

type -> _type

Also for the Content model itself:
https://github.com/pulp/pulp/blob/f9707edde3201e61a454efc395ad2d3e3d628f9b/pulpcore/pulpcore/app/models/content.py#L117-L118

notes -> _notes
artifacts -> _artifacts

After changing the field names, a lot of other code will need to be fixed likewise. Serializers and Django ORM queries will need to use the new names, to start with.

Details

This will be a backwards incompatible Beta change for both plugin writers and users. As such, the PR needs the 'breaking-changes', 'rest-API', and 'plugin-writer' labels.

As part of this issue, we should also switch to using 'pk' instead of 'id' in all Django ORM queries. 'pk' is a psuedonym for whatever the Primary Key field is set to, and will work no matter what said field is named. I would recommend searching for ".id", "id__in", and "id=" to make sure all of them are found, although that may not find all of them.

After making ^ change, go through pulp/pulp and update any references to the other field names.

After changing this in Pulpcore, we will need to go through each of the plugins (file, python, docker, rpm, ansible, + plugin_template) and do the same thing (replace usages of 'id' with 'pk' and other renamed fields with _field) in each of those. Link them back to this issue with "re" in the commit message.

[0] https://www.redhat.com/archives/pulp-dev/2018-August/msg00019.html


Related issues

Blocks RPM Support - Refactor #4207: Rename "update_type" and "errata_id" to "type" and "id", as they are named in createrepo_cCLOSED - CURRENTRELEASE

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>
Blocks Pulp - Task #4067: Commit migrations to source controlCLOSED - CURRENTRELEASE

<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>

Associated revisions

Revision cf30f2e9 View on GitHub
Added by CodeHeeler almost 3 years ago

Prepend pulpcore Content model fields with _

Prepend all pulpcore model fields in the Content model hierarchy with _ (e.g. '_type', '_id', '_notes')

Required PR: https://github.com/pulp/pulp_file/pull/148

ref #4206 https://pulp.plan.io/issues/4206

Revision cf30f2e9 View on GitHub
Added by CodeHeeler almost 3 years ago

Prepend pulpcore Content model fields with _

Prepend all pulpcore model fields in the Content model hierarchy with _ (e.g. '_type', '_id', '_notes')

Required PR: https://github.com/pulp/pulp_file/pull/148

ref #4206 https://pulp.plan.io/issues/4206

Revision 349fdf8b View on GitHub
Added by CodeHeeler almost 3 years ago

Prepend Content model hierarchy with _

Prepend all pulpcore model fields in the Content model hierarchy with _ and do the same for all plugins reliant on them.

Required PR: https://github.com/pulp/pulp/pull/3798

re #4206 https://pulp.plan.io/issues/4206

Revision 342fe67b View on GitHub
Added by CodeHeeler almost 3 years ago

Prepend Content model hierarchy with _

Prepend all pulpcore model fields in the Content model hierarchy with _ and do the same for all plugins reliant on them.

Required PR: https://github.com/pulp/pulp/pull/3798

re #4206 https://pulp.plan.io/issues/4206

Revision 25c41c47 View on GitHub
Added by CodeHeeler almost 3 years ago

Prepend Content model hierarchy with _

Prepend all pulpcore model fields in the Content model hierarchy with _ and do the same for all plugins reliant on them.

Required PR: https://github.com/pulp/pulp/pull/3798

re #4206 https://pulp.plan.io/issues/4206

History

#1 Updated by dalley about 3 years ago

A side effect of this change will be that accidentally using 'id' in a Django ORM query will not behave as intended. If this becomes a problem, I would suggest creating a lint tool that searches for this pattern and reminds the programmer to use 'pk' instead.

#2 Updated by dalley about 3 years ago

  • Description updated (diff)

#3 Updated by dalley about 3 years ago

  • Blocks Refactor #4207: Rename "update_type" and "errata_id" to "type" and "id", as they are named in createrepo_c added

#4 Updated by dalley about 3 years ago

  • Tags Pulp 3 RC Blocker added

#5 Updated by daviddavis about 3 years ago

  • Groomed changed from No to Yes
  • Sprint Candidate changed from No to Yes

#6 Updated by jortel@redhat.com about 3 years ago

  • Sprint set to Sprint 46

#7 Updated by amacdona@redhat.com about 3 years ago

It looks like https://pulp.plan.io/issues/3704 is a dupe, but I'm not clear what the exact overlap is. Please have a look at both issues when assigning this one.

#8 Updated by amacdona@redhat.com about 3 years ago

  • Has duplicate Task #3704: Make MasterModel attributes private using leading underscores added

#9 Updated by dalley almost 3 years ago

  • Description updated (diff)

#10 Updated by dalley almost 3 years ago

  • Description updated (diff)

#11 Updated by dalley almost 3 years ago

  • Has duplicate deleted (Task #3704: Make MasterModel attributes private using leading underscores)

#12 Updated by dalley almost 3 years ago

  • Subject changed from Prepend all pulpcore model fields with _ (e.g. '_type', '_id', '_notes') to Prepend all plugin-api pulpcore model fields with _ (e.g. '_type', '_id', '_notes')

#13 Updated by dalley almost 3 years ago

  • Subject changed from Prepend all plugin-api pulpcore model fields with _ (e.g. '_type', '_id', '_notes') to Prepend all pulpcore model fields in the Content model hierarchy with _ (e.g. '_type', '_id', '_notes')

#14 Updated by CodeHeeler almost 3 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to CodeHeeler

#15 Updated by daviddavis almost 3 years ago

  • Blocks Task #4067: Commit migrations to source control added

#17 Updated by CodeHeeler almost 3 years ago

  • Status changed from ASSIGNED to POST

#18 Updated by rchan almost 3 years ago

  • Sprint changed from Sprint 46 to Sprint 47

#19 Updated by dalley almost 3 years ago

  • Status changed from POST to MODIFIED

I think that should be everything. You updated file and python plugins and core, david updated RPM, I updated the plugin template and the ansible plugin, and the docker plugin didn't need anything done.

#20 Updated by daviddavis over 2 years ago

  • Sprint/Milestone set to 3.0.0

#21 Updated by bmbouter over 2 years ago

  • Tags deleted (Pulp 3, Pulp 3 RC Blocker)

#22 Updated by bmbouter almost 2 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Please register to edit this issue

Also available in: Atom PDF