Skip to content

Comments

Fix #2626: Duplicate scheduled year for single day events#2934

Open
iampujan wants to merge 4 commits intopython:mainfrom
iampujan:feature/issue-2626-duplicate-event-year
Open

Fix #2626: Duplicate scheduled year for single day events#2934
iampujan wants to merge 4 commits intopython:mainfrom
iampujan:feature/issue-2626-duplicate-event-year

Conversation

@iampujan
Copy link
Contributor

Fixes #2626. Removed duplicate render for dt_start|date:"Y" in time_tag.html when single_day is true. Includes a unit test to enforce single-year rendering for same day events.

- Removes redundant rendering of next_time.dt_start year block inside time_tag.html for single_day events
- Adds unit tests to ensure the DOM output for single day events generates the year precisely once.
Copilot AI review requested due to automatic review settings February 22, 2026 09:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes duplicate year rendering for single-day events in the shared events time tag template, and adds a unit test intended to prevent regressions (Issue #2626).

Changes:

  • Remove duplicate dt_start|date:"Y" rendering in time_tag.html when next_time.single_day is true.
  • Add a template-focused unit test to assert single-year rendering for single-day future-year events.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/events/templates/events/includes/time_tag.html Removes the extra year <span> in the single-day rendering path.
apps/events/tests/test_templates.py Adds a new test to validate the single-day template doesn’t duplicate the year.
Comments suppressed due to low confidence (2)

apps/events/tests/test_templates.py:32

  • next_time.dt_start/dt_end are timezone-aware datetimes in normal operation (model fields use timezone.now() and managers call convert_dt_to_aware). Here the mock uses naive datetime.datetime(...), which can lead to inconsistent output depending on timezone settings. Consider using django.utils.timezone.make_aware(...) (or tzinfo=datetime.UTC) for the mock datetimes to match production behavior.
                self.dt_start = datetime.datetime(future_year, 5, 25, 12, 0)
                self.dt_end = datetime.datetime(future_year, 5, 25, 14, 0)
                self.single_day = True
                self.all_day = False
                self.valid_dt_end = True

apps/events/tests/test_templates.py:51

  • The assertion counts year occurrences by splitting on an exact whitespace/indentation pattern. This is brittle (minor template formatting changes will break the test) and doesn’t actually verify “visible” vs attribute text robustly. Prefer parsing the rendered HTML (e.g., BeautifulSoup) and asserting the year appears exactly once as a text node within the span#start-..., or use a whitespace-tolerant regex like >\s*YEAR\s*</span>.
        # The year should only appear visibly once in the output (not counting the datetime ISO tag).
        year_str = str(future_year)
        # Using string splitting to exclude the `datetime="2027...` occurrence by checking how many times
        # it appears wrapped with whitespace or inside a span.
        visible_occurrences = rendered.split(">\n            " + year_str + "\n        </span>")
        self.assertEqual(
            len(visible_occurrences) - 1,
            1,
            f"Expected the visible span containing {year_str} to appear exactly once, but it was duplicated: {rendered}"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 24, 2026 09:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

apps/events/tests/test_templates.py:52

  • The assertion is very brittle because it depends on the exact whitespace/newline formatting emitted by the template. A small indentation/formatting change in time_tag.html will break this test even if the behavior is still correct. Prefer asserting on structure (e.g., count of <span id="start-..."> occurrences) or use a whitespace-tolerant regex that matches the year inside a <span>.
        rendered = render_to_string("events/includes/time_tag.html", context)
        
        # The year should only appear visibly once in the output (not counting the datetime ISO tag).
        year_str = str(future_year)
        # Using string splitting to exclude the `datetime="2027...` occurrence by checking how many times
        # it appears wrapped with whitespace or inside a span.
        visible_occurrences = rendered.split(">\n            " + year_str + "\n        </span>")
        self.assertEqual(
            len(visible_occurrences) - 1,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate scheduled year for single day events whose scheduled year is rendered

1 participant