Skip to content

Commit

Permalink
Merge pull request #454 from xchem/m2ms-1218-user-fix
Browse files Browse the repository at this point in the history
Caters for None User ID
  • Loading branch information
alanbchristie authored Dec 1, 2023
2 parents 7a879ba + cb07f0a commit c5812ea
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions viewer/cset_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ def set_descriptions(self, filename, computed_set: ComputedSet) -> List[str]:
return mols

def task(self) -> ComputedSet:
user = User.objects.get(id=self.user_id)
sdf_filename = str(self.sdf_filename)

set_name = ''.join(
Expand Down Expand Up @@ -493,7 +492,12 @@ def task(self) -> ComputedSet:
+ '-'
+ "".join(self.submitter_method.split())
)
computed_set.owner_user = user
if self.user_id:
computed_set.owner_user = User.objects.get(id=self.user_id)
else:
# The User ID may only be None if AUTHENTICATE_UPLOAD is False.
# Here the ComputedSet owner will take on a default (anonymous) value.
assert settings.AUTHENTICATE_UPLOAD is False
computed_set.save()

# set descriptions and get all other mols back
Expand All @@ -502,7 +506,7 @@ def task(self) -> ComputedSet:
)

# process every other mol
for i in range(0, len(mols_to_process)):
for i in range(len(mols_to_process)):
self.process_mol(
mols_to_process[i],
self.target,
Expand Down
2 changes: 2 additions & 0 deletions viewer/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def process_compound_set(validate_output):
for cset in csets:
cset.delete()

# We expect a User ID, but it may be None.
# If AUTHENTICATE_UPLOAD is False the User ID will be None.
save_mols = MolOps(
user_id=params['user_id'],
sdf_filename=params['sdf'],
Expand Down
3 changes: 2 additions & 1 deletion viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ def post(self, request):
update_set = request.POST.get('update_set')

logger.info(
'+ UploadCSet POST choice="%s" target="%s" update_set="%s"',
'+ UploadCSet POST user.id=%s choice="%s" target="%s" update_set="%s"',
user.id,
choice,
target,
update_set,
Expand Down

0 comments on commit c5812ea

Please sign in to comment.