Fix #2626: Duplicate scheduled year for single day events#2934
Open
iampujan wants to merge 4 commits intopython:mainfrom
Open
Fix #2626: Duplicate scheduled year for single day events#2934iampujan wants to merge 4 commits intopython:mainfrom
iampujan wants to merge 4 commits intopython:mainfrom
Conversation
- 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.
There was a problem hiding this comment.
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 intime_tag.htmlwhennext_time.single_dayis 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_endare timezone-aware datetimes in normal operation (model fields usetimezone.now()and managers callconvert_dt_to_aware). Here the mock uses naivedatetime.datetime(...), which can lead to inconsistent output depending on timezone settings. Consider usingdjango.utils.timezone.make_aware(...)(ortzinfo=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>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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.htmlwill 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2626. Removed duplicate render for
dt_start|date:"Y"intime_tag.htmlwhensingle_dayis true. Includes a unit test to enforce single-year rendering for same day events.