Skip to content

Commit

Permalink
fix: handle surprising file metadata states
Browse files Browse the repository at this point in the history
- osfstorage FileVersion with null creator
- osfstorage file without versions (fix bug in `_hashes`)
  • Loading branch information
aaxelb committed Aug 24, 2023
1 parent d1b2b46 commit a5110a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 6 additions & 4 deletions addons/osfstorage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ class OsfStorageFile(OsfStorageFileNode, File):

@property
def _hashes(self):
latest_version = self.versions.latest('identifier')
if not latest_version:
try:
latest_version = self.versions.latest('identifier')
except FileVersion.DoesNotExist:
return None
return {
'sha1': latest_version.metadata.get('sha1', ''),
Expand All @@ -243,8 +244,9 @@ def _hashes(self):

@property
def last_known_metadata(self):
latest_version = self.versions.latest('identifier')
if not latest_version:
try:
latest_version = self.versions.latest('identifier')
except FileVersion.DoesNotExist:
size = None
else:
size = latest_version.size
Expand Down
3 changes: 2 additions & 1 deletion osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ def gather_versions(focus):

def _gather_fileversion(fileversion, fileversion_iri):
yield (fileversion_iri, RDF.type, OSF.FileVersion)
yield (fileversion_iri, DCTERMS.creator, OsfFocus(fileversion.creator))
if fileversion.creator is not None:
yield (fileversion_iri, DCTERMS.creator, OsfFocus(fileversion.creator))
yield (fileversion_iri, DCTERMS.created, fileversion.created)
yield (fileversion_iri, DCTERMS.modified, fileversion.modified)
yield (fileversion_iri, DCTERMS['format'], fileversion.content_type)
Expand Down

0 comments on commit a5110a5

Please sign in to comment.