-
Notifications
You must be signed in to change notification settings - Fork 1
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
Application priority bug #1694
base: master
Are you sure you want to change the base?
Application priority bug #1694
Conversation
…ty is reorganized
backend/samfundet/signals.py
Outdated
@receiver(pre_save, sender=RecruitmentApplication) | ||
def handle_reactivation(sender: RecruitmentApplication, instance: RecruitmentApplication, **kwargs) -> None: | ||
# Only perform reactivation logic if this is an update (i.e. the object is not new) | ||
# For new objects, instance._state.adding is True, so we skip this block. | ||
if not instance._state.adding: | ||
try: | ||
# Attempt to fetch the existing record from the database using its primary key. | ||
old_instance = RecruitmentApplication.objects.get(pk=instance.pk) | ||
except RecruitmentApplication.DoesNotExist: | ||
# If the record does not exist in the database, set old_instance to None. | ||
# This might occur if the record was deleted or not yet committed. | ||
old_instance = None | ||
# If we have an existing record, and it was previously withdrawn, | ||
# but now the updated instance is not withdrawn, then the application is being reactivated. | ||
if old_instance and old_instance.withdrawn and not instance.withdrawn: | ||
# Call a helper method to set the reactivated application's priority | ||
# (e.g., by assigning it the lowest active priority plus one). | ||
RecruitmentApplication._set_reactivated_priority(instance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure I like this solution
if self.withdrawn: | ||
# when an application is witdrawn the organize_priorities_on_withdrawal signal is called, this must happen post save | ||
# this if-statement makes sure that the recruiter_status/priority is "resets" on withdrawal | ||
# TODO: DO WE WANT TO SET IT TO NOT WANTED AND AUTOMATIC REJECTION? WOULD NOT_SET AND NOT_SET BE BETTER? | ||
self.recruiter_priority = RecruitmentPriorityChoices.NOT_WANTED | ||
|
||
self.recruiter_status = RecruitmentStatusChoices.AUTOMATIC_REJECTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: do we actually want to set NOT_WANTED and AUTOMATIC_REJECTION here?
def update_applicant_state(self) -> None: | ||
# TODO: DO WE WANT TO CONSIDER WITHDRAWN APPLICATIONS HERE: | ||
applications = RecruitmentApplication.objects.filter(user=self.user, recruitment=self.recruitment).order_by('applicant_priority') | ||
# Get top priority | ||
top_wanted = applications.filter(recruiter_priority=RecruitmentPriorityChoices.WANTED).order_by('applicant_priority').first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: should we add withdraw=False on the filters on line 488 and 490?
💡 replaced this:#1594
There was a bug which made applicant priority of positions incorrect. This is because when priority is manipulated the total count of applications was including withdrawn applications.
This was the case both when a new application was created, but also when applications where withdrawn.
There also is a bug where the priority is set incorrectly in the scenario when the applicant applies for a position which they previously had withdrawn the application from (could also be described as "re-activating" the application). The application gets the priority it had when it was withdrawn, which seems like unwanted behavior. I think the behavior should be that the "re-activated" application should get the lowest priority, like when the applicant applies for a position for the first time.
I feel that the way we handle withdrawal (setting a flag to false) is prone to error, would it be better to just delete when an applicant withdraws?