mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-28 21:41:45 -05:00
Avoid extra query when serialising Template created_by
It’s a UUID column, but by default Marshmallow wants to select the id from the users table, not from the templates table, because the two are foreign-keyed. Adding the property explicity like this forces it to select from the `created_by_id` column, but still serialises it to the `created_by` field to avoid any breaking change.
This commit is contained in:
@@ -343,7 +343,9 @@ class BaseTemplateSchema(BaseSchema):
|
||||
|
||||
class TemplateSchema(BaseTemplateSchema):
|
||||
|
||||
created_by = field_for(models.Template, 'created_by', required=True)
|
||||
created_by_id = field_for(
|
||||
models.Template, 'created_by_id', dump_to='created_by', dump_only=True
|
||||
)
|
||||
process_type = field_for(models.Template, 'process_type')
|
||||
redact_personalisation = fields.Method("redact")
|
||||
|
||||
@@ -357,6 +359,9 @@ class TemplateSchema(BaseTemplateSchema):
|
||||
if not subject or subject.strip() == '':
|
||||
raise ValidationError('Invalid template subject', 'subject')
|
||||
|
||||
class Meta(BaseTemplateSchema.Meta):
|
||||
exclude = BaseTemplateSchema.Meta.exclude + ('created_by',)
|
||||
|
||||
|
||||
class TemplateHistorySchema(BaseSchema):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user