Skip to content

Commit

Permalink
Do not try to fetch url for a null FileField value, preventing transf…
Browse files Browse the repository at this point in the history
…er failures for nullable FileFields
  • Loading branch information
emilytoppm authored and gasman committed Sep 24, 2020
1 parent bf0b70e commit 4fd1ef2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion wagtail_transfer/field_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def update_object_references(self, value, destination_ids_by_source):

class FileAdapter(FieldAdapter):
def serialize(self, instance):
url = self.field.value_from_object(instance).url
value = self.field.value_from_object(instance)
if not value:
return None
url = value.url
if settings.MEDIA_URL.startswith('/'):
# Using a relative media url. ie. /media/
# Prepend the BASE_URL to turn this into an absolute URL
Expand All @@ -177,6 +180,8 @@ def serialize(self, instance):
}

def populate_field(self, instance, value, context):
if not value:
return None
imported_file = context.imported_files_by_source_url.get(value['download_url'])
if imported_file is None:

Expand Down

0 comments on commit 4fd1ef2

Please sign in to comment.