Revert "Avoid extra query when serialising Template created_by"

This reverts commit 58a9862cd1.

That commit tried to optimize the fetch template query by

However it had the side effect of making Marshmallow ignore `created_by`
when loading the JSON in the post request. So the field on the model was
never being updated, just copied from the original template.

The quick way of getting things to work again is to revert this
optimisation.

There’s probably some Marshmallow magic we could use to avoid the extra
query and still have created_by not be ignored.

It does mean we’re introducing an extra query, but I’m not too fussed
about that since the caching seems to be working well.
This commit is contained in:
Chris Hill-Scott
2020-06-29 11:16:37 +01:00
parent 02e5ff61a4
commit f541ad42d6

View File

@@ -356,9 +356,7 @@ class BaseTemplateSchema(BaseSchema):
class TemplateSchema(BaseTemplateSchema, UUIDsAsStringsMixin):
created_by_id = field_for(
models.Template, 'created_by_id', dump_to='created_by', dump_only=True
)
created_by = field_for(models.Template, 'created_by', required=True)
process_type = field_for(models.Template, 'process_type')
redact_personalisation = fields.Method("redact")
@@ -372,9 +370,6 @@ class TemplateSchema(BaseTemplateSchema, UUIDsAsStringsMixin):
if not subject or subject.strip() == '':
raise ValidationError('Invalid template subject', 'subject')
class Meta(BaseTemplateSchema.Meta):
exclude = BaseTemplateSchema.Meta.exclude + ('created_by',)
class TemplateSchemaNoDetail(TemplateSchema):
class Meta(TemplateSchema.Meta):