Skip to content

Commit

Permalink
Fix failing autoname when new nickname already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
rossant committed Jan 24, 2023
1 parent b118cc0 commit dacd33c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion alyx/subjects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,11 @@ def new_litter_autoname(self):
def new_subject_autoname(self):
self.subject_autoname_index = self.subject_autoname_index + 1
self.save()
return '%s_%04d' % (self.nickname, self.subject_autoname_index)
new_name = '%s_%04d' % (self.nickname, self.subject_autoname_index)
if Subject.objects.filter(nickname=new_name).count() > 0:
return self.new_subject_autoname()
assert Subject.objects.filter(nickname=new_name).count() == 0
return new_name

def set_autoname(self, obj):
if isinstance(obj, BreedingPair):
Expand Down

0 comments on commit dacd33c

Please sign in to comment.