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

Application priority bug #1694

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Snorre98
Copy link
Contributor

@Snorre98 Snorre98 commented Feb 14, 2025

💡 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?

@Snorre98 Snorre98 linked an issue Feb 14, 2025 that may be closed by this pull request
1 task
@Snorre98 Snorre98 self-assigned this Feb 14, 2025
@Snorre98 Snorre98 marked this pull request as ready for review February 14, 2025 21:08
@Snorre98 Snorre98 added the help wanted Extra attention is needed. label Feb 14, 2025
Comment on lines 97 to 114
@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)
Copy link
Contributor Author

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

@Snorre98 Snorre98 changed the title makes sure that only "active" applications are considered when priori… Application priority bug Feb 14, 2025
Comment on lines 449 to 455
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
Copy link
Contributor Author

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?

Comment on lines 497 to 501
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()
Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] withdrawn application showing up for applicatn
1 participant