Refactor #4206

Updated by dalley almost 3 years ago

h3. Motivations

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

2. Allow users
Pulpcore adds a number of fields to easily see models which attributes are from pulpcore and therefore common likely (or known) to all conflict with the names of fields on certain content types. For instance, errata contain fields named 'id' and 'type', which conflict with the default field names for the pk field and a field used by the MasterModel mechanism, respectively.

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. Thus:

h3. Changes

* A primary key field would be created on the Model fields here in base model named '_id' to replace the following ways: default-generated 'id' one.

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

As well as the
* 'type' on MasterModel "type" field here:

type -> _type

Also for the Content model itself:
would be renamed to '_type'

notes -> _notes
* 'notes' would be renamed to '_notes'
artifacts -> _artifacts

After changing the field names, a lot of other code will need
* And so forth. This is not intended to be fixed likewise. Serializers and Django ORM queries will need to use the new names, to start with.

h3. Details
an exhaustive list.

This will be a backwards incompatible Beta change is already the case for both plugin writers some fields, such as '_created' and users. As such, the PR needs the 'breaking-changes', 'rest-API', and 'plugin-writer' labels. '_last_updated'

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.

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) 'pk') in each of those. Link them back to this issue with "re" in the commit message.