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
This commit is contained in:
Oliver 2023-01-27 14:50:41 +11:00 committed by GitHub
parent cb518ddde6
commit 83eaa6ef79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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'))

View File

@ -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"""