Skip to content

Commit

Permalink
Revert to create keys, add saves to dx error in prod
Browse files Browse the repository at this point in the history
Disentangling these keys from authorization is too complex
and risky for a quick fix, but they are necessary. This commit adds
save() points to try to diagnose which field is causing an issue.
  • Loading branch information
madprime committed Dec 22, 2020
1 parent 64cb07b commit 31c5498
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions data_import/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,9 @@ def __str__(self):
return str("{0}:{1}:{2}").format(self.user, self.source, self.file)

def download_url(self, request):
# 20201222 MPB: commenting these out because generate_key is producing "out of range" errors;
# unclear why, but this was an incomplete logging effort we ended up not using.
#
# key = self.generate_key(request)
key = self.generate_key(request)
url = full_url(reverse("data-management:datafile-download", args=(self.id,)))
# return "{0}?key={1}".format(url, key)
return url
return "{0}?key={1}".format(url, key)

@property
def file_url_as_attachment(self):
Expand All @@ -116,9 +112,13 @@ def generate_key(self, request):
Generate new link expiration key
"""
new_key = DataFileKey(datafile_id=self.id)
new_key.save()

if request:
# Log the entity that is requesting the key be generated
new_key.ip_address = get_ip(request)
new_key.save()

try:
new_key.access_token = request.query_params.get("access_token", None)
except (AttributeError, KeyError):
Expand All @@ -128,7 +128,8 @@ def generate_key(self, request):
except AttributeError:
# We do not have an accessing project
new_key.project_id = None
new_key.save()
new_key.save()

return new_key.key

@property
Expand Down

0 comments on commit 31c5498

Please sign in to comment.