Project

Profile

Help

Refactor #1555

Updated by semyers about 8 years ago

ModelSerializer knows how Currently, mongoengine Document models that use a remapped id field (for example, repos use the repo_id to translate model fields when crafting responses, store their id field) don't have a common attribute identifying the field used as that model's ID (e.g. repo_id 'zoo', not its object UUID). Currently, the only way to get the name of this field is to go through the model's serializer (if it has one), inspect the serializer's _remapped_fields dict (if it has one), and also how pull out the dict key (if it has one and only one) to figure out which field is the model's ID field. 

 This is mainly required because serializers only handle pulp's *responses*, but we need a way to reliably translate fields when parsing incoming requests. Unfortunately, it currently only exposes requests to use the latter behavior via correct field names (e.g. turn the request's 'id' param into 'repo_id' if the api is dealing with a Repository) 

 All mongoengine models should have a default serializer (this is issue #1509), but the model itself should be keeping track of which field contains its "translate_criteria" method. The "_translate" and "_translate_filters" methods are generally useful, and ID. Probably a model class-level constant such as ID_FIELD should be made public. required.

Back