From bc68cfddaed5c4116d8cea62289fe3228ed16dac Mon Sep 17 00:00:00 2001 From: Jhony Lucas Date: Tue, 6 Aug 2024 14:46:22 -0300 Subject: [PATCH] fix: Use item.get() method to retrieve field values in populate.py (#650) --- backend/apps/core/management/commands/populate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/apps/core/management/commands/populate.py b/backend/apps/core/management/commands/populate.py index f0ad4247..e2216db4 100644 --- a/backend/apps/core/management/commands/populate.py +++ b/backend/apps/core/management/commands/populate.py @@ -205,7 +205,7 @@ def create_instance(self, model, item): for field in model._meta.get_fields(): if isinstance(field, models.ForeignKey): field_name = f"{field.name}_id" - current_value = item[field_name] + current_value = item.get(field_name) if current_value is None: continue @@ -349,7 +349,7 @@ def handle(self, *args, **kwargs): instance = retry["instance"] field_name = retry["field_name"] related_table_name = retry["table_name"] - current_value = item[field_name] + current_value = item.get(field_name) reference = self.references.get(related_table_name, current_value)