Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make professor aliases unique #82

Merged
merged 4 commits into from
Feb 6, 2023
Merged

Make professor aliases unique #82

merged 4 commits into from
Feb 6, 2023

Conversation

nsandler1
Copy link
Member

No description provided.

@tybug
Copy link
Contributor

tybug commented Jan 30, 2023

we should also change merging professors to check for duplicate name in alias, instead of leaving it to throw a 500 error. Not sure what the best approach here is. For now we can probably just refuse to merge a professor if it would create a duplicate alias, and we can manually fix things up in the django admin panel if necessary? Depends how often this comes up.

@nsandler1
Copy link
Member Author

nsandler1 commented Jan 31, 2023

Good point, though I don't think we need to abort the merge. Since the problem alias already exists as an alias of the merge target, we can just delete it from the merge subject's aliases before the aliases are merged.

@nsandler1
Copy link
Member Author

nsandler1 commented Jan 31, 2023

Disregard my last comment, I realized we already have a check in place to (almost) prevent your concern from happening (in admin.py):

170  ProfessorAlias.objects.filter(professor=merge_subject).update(professor=merge_target)
171
172  aliases = ProfessorAlias.objects.filter(alias=merge_subject.name, professor=merge_target)
173  if not aliases.exists():
174       ProfessorAlias(alias=merge_subject.name, professor=merge_target).save()

I should probably change the aliases query to only filter on the alias, not the alias and the professor. Other than that, this fragment should prevent any integrity violations. To clarify, even the initial bulk update won't cause any issues because we currently don't have any duplicate aliases (I checked) and the conditional checks for existing aliases before creating a new one.

EDIT: #84 changes line 172 to aliases = ProfessorAlias.objects.filter(alias=merge_subject.name) which does prevent your concern from happening

@nsandler1 nsandler1 added the priority Should be considered a priority label Feb 6, 2023
@tybug
Copy link
Contributor

tybug commented Feb 6, 2023

yep, not creating any alias at all in a case like this sounds like a good approach.

@tybug tybug merged commit 62aeeb4 into master Feb 6, 2023
@tybug tybug deleted the unique-aliases branch February 6, 2023 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority Should be considered a priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants