Skip to content

fix: ensure getDecisionDate indexer always returns DateTime - #546

Open
WBoudabous wants to merge 2 commits into
2.9.xfrom
SUP-52501_decision_fix_date_indexer
Open

fix: ensure getDecisionDate indexer always returns DateTime#546
WBoudabous wants to merge 2 commits into
2.9.xfrom
SUP-52501_decision_fix_date_indexer

Conversation

@WBoudabous

@WBoudabous WBoudabous commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

This PR ensures that the getDecisionDate indexer always returns a DateTime.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed decision date filtering to consistently return properly formatted dates from all data sources, including imported meeting information. This ensures accurate and reliable date-based filtering throughout the application.

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 39dadaa3-6313-4e3f-8229-15ec9d9b0a5b

📥 Commits

Reviewing files that changed from the base of the PR and between fc1fc65 and 8a7bd01.

📒 Files selected for processing (1)
  • news/SUP-52501.fix
✅ Files skipped from review due to trivial changes (1)
  • news/SUP-52501.fix

📝 Walkthrough

Walkthrough

The genericlicence_decisiondate indexer in src/Products/urban/indexes.py was updated to defensively handle the extra_include_meeting "date" field using .get() and truthiness checking before DateTime conversion. A corresponding fix news entry documents the correction ensuring the indexer always returns a DateTime object.

Changes

Cohort / File(s) Summary
Date Indexer Defensive Handling
src/Products/urban/indexes.py
Updated genericlicence_decisiondate to use .get("date") with truthiness validation and explicit DateTime conversion, replacing direct key access without value validation.
Fix Documentation
news/SUP-52501.fix
Added news entry documenting that decisionDate filter behavior is corrected by ensuring the getDecisionDate indexer always returns a DateTime from PloneMeeting data.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A date field once lay without care,
But now we check it with a thorough stare—
With .get() and truthiness we bind,
To DateTime conversions, robust and kind!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: ensuring the getDecisionDate indexer always returns DateTime, which is demonstrated in the code changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch SUP-52501_decision_fix_date_indexer

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
docs/CHANGES.rst (1)

13-20: Avoid duplicate Bug fixes: subsections for the same release entry.

Under 2.9.17, this adds a second Bug fixes: block. Please merge both items into one block (or move to a news fragment if your release process enforces that).

Proposed cleanup
-Bug fixes:
-
-- Fix decisionDate filter: ensure getDecisionDate indexer always 
-returns a DateTime (including PloneMeeting data).
-[WBoudabous] (SUP-52501)
-
-
-Bug fixes:
+Bug fixes:
+
+- Fix decisionDate filter: ensure getDecisionDate indexer always
+  returns a DateTime (including PloneMeeting data).
+  [WBoudabous] (SUP-52501)
 
 - Fix missing import
   [jchandelle] (SUP-52327)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/CHANGES.rst` around lines 13 - 20, The CHANGES.rst entry for release
2.9.17 contains a duplicated "Bug fixes:" subsection; consolidate them by
merging the two "Bug fixes:" blocks into a single subsection (combine the line
mentioning "Fix decisionDate filter: ensure getDecisionDate indexer always
returns a DateTime (including PloneMeeting data)." with the existing Bug fixes
list) or, if your release workflow requires, move the new item into an
appropriate news fragment instead; ensure the final 2.9.17 section has only one
"Bug fixes:" header and includes the getDecisionDate indexer note.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Products/urban/indexes.py`:
- Around line 277-280: The fallback path still returns a plain datetime.date and
doesn't safely access the PloneMeeting data; update the logic in the function
that builds the index value (the block referencing linked_pm_items and calling
decision_event.getDecisionDate()/getEventDate()) to: 1) guard access to
linked_pm_items[0]["extra_include_meeting"] by using
.get("extra_include_meeting") and then .get("date") to avoid
KeyError/AttributeError; 2) when a date string is present create and return a
DateTime(date_str); and 3) for the existing fallbacks call
decision_event.getDecisionDate() and decision_event.getEventDate() and, if they
are a datetime.date or datetime.datetime, convert them to a DateTime instance
before returning (use the DateTime constructor), so the function always returns
a DateTime. Ensure DateTime is imported where used.

---

Nitpick comments:
In `@docs/CHANGES.rst`:
- Around line 13-20: The CHANGES.rst entry for release 2.9.17 contains a
duplicated "Bug fixes:" subsection; consolidate them by merging the two "Bug
fixes:" blocks into a single subsection (combine the line mentioning "Fix
decisionDate filter: ensure getDecisionDate indexer always returns a DateTime
(including PloneMeeting data)." with the existing Bug fixes list) or, if your
release workflow requires, move the new item into an appropriate news fragment
instead; ensure the final 2.9.17 section has only one "Bug fixes:" header and
includes the getDecisionDate indexer note.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 11a09c01-7a3d-45fa-9436-4e76ba875461

📥 Commits

Reviewing files that changed from the base of the PR and between 5fabb4d and fc1fc65.

📒 Files selected for processing (2)
  • docs/CHANGES.rst
  • src/Products/urban/indexes.py

Comment on lines +277 to 280
date_str = linked_pm_items[0]["extra_include_meeting"].get("date")
if date_str:
return DateTime(date_str)
return decision_event.getDecisionDate() or decision_event.getEventDate()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

getDecisionDate is still not guaranteed to return DateTime in all paths.

The new PloneMeeting path is improved, but the fallback at Line [263]-Line [275] still returns datetime.date, which violates the PR objective and can conflict with DateIndex. Also, linked_pm_items[0]["extra_include_meeting"] is still not safely guarded.

Proposed fix
@@
-            if brain and brain[0].getDecisionDate:
-                old_decision_date = brain[0].getDecisionDate
-                if type(old_decision_date) is DateTime:
-                    decision_date = date(
-                        old_decision_date.year(),
-                        old_decision_date.month(),
-                        old_decision_date.day(),
-                    )
-                else:
-                    decision_date = date(
-                        old_decision_date.year,
-                        old_decision_date.month,
-                        old_decision_date.day,
-                    )
-                return decision_date
+            if brain and brain[0].getDecisionDate:
+                old_decision_date = brain[0].getDecisionDate
+                if isinstance(old_decision_date, DateTime):
+                    return old_decision_date
+                return DateTime(old_decision_date.isoformat())
         if linked_pm_items:
-            date_str = linked_pm_items[0]["extra_include_meeting"].get("date")
+            meeting = linked_pm_items[0].get("extra_include_meeting") or {}
+            date_str = meeting.get("date")
             if date_str:
                 return DateTime(date_str)
-        return decision_event.getDecisionDate() or decision_event.getEventDate()
+        decision_date = decision_event.getDecisionDate() or decision_event.getEventDate()
+        if decision_date and not isinstance(decision_date, DateTime):
+            decision_date = DateTime(decision_date.isoformat())
+        return decision_date
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Products/urban/indexes.py` around lines 277 - 280, The fallback path
still returns a plain datetime.date and doesn't safely access the PloneMeeting
data; update the logic in the function that builds the index value (the block
referencing linked_pm_items and calling
decision_event.getDecisionDate()/getEventDate()) to: 1) guard access to
linked_pm_items[0]["extra_include_meeting"] by using
.get("extra_include_meeting") and then .get("date") to avoid
KeyError/AttributeError; 2) when a date string is present create and return a
DateTime(date_str); and 3) for the existing fallbacks call
decision_event.getDecisionDate() and decision_event.getEventDate() and, if they
are a datetime.date or datetime.datetime, convert them to a DateTime instance
before returning (use the DateTime constructor), so the function always returns
a DateTime. Ensure DateTime is imported where used.

@WBoudabous
WBoudabous requested a review from mpeeters April 16, 2026 12:26
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.

1 participant