From f541ad42d67b8e222997debdbfe647a0bf8c501a Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 29 Jun 2020 11:16:37 +0100 Subject: [PATCH] Revert "Avoid extra query when serialising Template created_by" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 58a9862cd1392c0c3384ce37d4b8eeb51dd7da32. 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. --- app/schemas.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/schemas.py b/app/schemas.py index 6199c14bd..3258c1c45 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -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):