From 83eaa6ef79acfa35f557404f04ce2e60765615b0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 27 Jan 2023 14:50:41 +1100 Subject: [PATCH] Bug fix for creating Part or Company via API (#4264) - If specified, the "remote_image" field is passed through to the __init__ method - Throws a 500 error - Solution is to explicitly ignore the provided field --- InvenTree/company/models.py | 11 +++++++++++ InvenTree/part/models.py | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 6add14d125..a7310390b0 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -94,6 +94,17 @@ class Company(MetadataMixin, models.Model): ] verbose_name_plural = "Companies" + def __init__(self, *args, **kwargs): + """Custom initialization routine for the Company model. + + Ensures that custom serializer fields (without matching model fields) are removed + """ + + # Remote image specified during creation via API + kwargs.pop('remote_image', None) + + super().__init__(*args, **kwargs) + name = models.CharField(max_length=100, blank=False, help_text=_('Company name'), verbose_name=_('Company name')) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 8b3d6055b7..1368c3f83b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -391,6 +391,17 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel): # For legacy reasons the 'variant_of' field is used to indicate the MPTT parent parent_attr = 'variant_of' + def __init__(self, *args, **kwargs): + """Custom initialization routine for the Part model. + + Ensures that custom serializer fields (without matching model fields) are removed + """ + + # Remote image specified during creation via API + kwargs.pop('remote_image', None) + + super().__init__(*args, **kwargs) + @staticmethod def get_api_url(): """Return the list API endpoint URL associated with the Part model"""