[Bug] Holiday import applies every region's holidays to everyone in the country (e.g. Scottish and NI holidays for English staff)

Open
#101 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python
Domain
backend, databases

Research direction

Start with chaotica_utils/views/holidays.py and inspect the holiday lookup methods, especially HolidayManager.get_date_list(). Trace how Holiday.subdivs is populated and how user country data reaches both lookup sites; the issue suggests several possible fixes, including adding a user subdivision field. Done means regional holidays are limited to applicable users and the country filter works as intended.

Written by the indexing model from the issue text.

Description

Summary

holiday_import_lib (chaotica_utils/views/holidays.py) imports holidays for every subdivision of the chosen country and stores them with country set and the subdivision codes in Holiday.subdivs. But nothing reads subdivs: users have no subdivision field, and both places that look up a user's holidays filter by country only:

Holiday.objects.filter(Q(country=self.country) | Q(country__isnull=True), ...)

Importing United Kingdom therefore marks these as holidays for every GB user:

  • 2 January
  • St Patrick's Day
  • Battle of the Boyne
  • St Andrew's Day
  • the Scottish summer bank holiday

This lowers effective working days and skews utilisation, availability and the scheduler for staff in England and Wales. The same applies to any country with regional holidays, such as Germany, Spain or Australia.

Related problems in the same code

  • The country filter is discarded: HolidayManager.get_date_list() calls matches.filter(country=country) without assigning the result, so it returns holidays for every country.
  • Only two years are imported: the importer covers the current and next year (years = [now.year, now.year + 1]), so admins must remember to re-run it every year. A note on the page, or a yearly task, would help.

Suggested fix

  • Add subdivision to the user, for example a CharField validated against holidays.country_holidays(country).subdivisions. Then filter Q(subdivs=[]) | Q(subdivs__contains=[user.subdivision]) alongside the country.
  • Or let the importer take a subdivision, and import only the national holidays plus that region's.
  • Fix get_date_list to assign the filtered queryset.
Dominant language
HTML
Stars
6
Forks
4
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from brainthee/CHAOTICA

All issues in brainthee/CHAOTICA

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.