Skip to content

URB-3704: Handle an empty list of NOTICe notifications#597

Open
daggelpop wants to merge 1 commit into
2.9.xfrom
URB-3704_empty_notification_list
Open

URB-3704: Handle an empty list of NOTICe notifications#597
daggelpop wants to merge 1 commit into
2.9.xfrom
URB-3704_empty_notification_list

Conversation

@daggelpop

@daggelpop daggelpop commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Only happens to municipalities freshly connected to the NOTICe streams, before receiving their first notification.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of REST responses with no NOTICe notifications.
    • The system now returns an empty notification list instead of producing an error when notification data is missing or empty.

@daggelpop daggelpop requested a review from mpeeters July 10, 2026 10:09
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The notice service now handles missing or empty notification data by returning an empty list, and the release notes document the change.

Changes

NOTICe notification handling

Layer / File(s) Summary
Defensive notification response handling
src/Products/urban/services/notice.py, news/URB-3704.bugfix
get_notifications() uses defensive access for notices.notice and returns an empty list when the response structure is absent or empty. A release note documents this behavior.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: mpeeters

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: handling empty NOTICe notification lists.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch URB-3704_empty_notification_list

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Products/urban/services/notice.py`:
- Around line 138-140: The tests for get_notifications() lack coverage for
responses missing notices or notice. Add a test case in test_notice.py with an
empty or incomplete response and assert get_notifications() returns [] without
raising an error.
🪄 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: 7a2424a6-84fb-4f8d-bdb5-e730d6592c39

📥 Commits

Reviewing files that changed from the base of the PR and between e9f04e4 and c717af3.

📒 Files selected for processing (2)
  • news/URB-3704.bugfix
  • src/Products/urban/services/notice.py

Comment on lines +138 to +140
notices_obj = result.get("notices") or {}
notices_list = notices_obj.get("notice") or []
return notices_list

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for tests exercising the empty/missing notices scenario.
rg -n -C3 'get_notifications' src/Products/urban/services/tests/test_notice.py

Repository: IMIO/Products.urban

Length of output: 474


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== notice.py outline =="
ast-grep outline src/Products/urban/services/notice.py --view expanded || true

echo
echo "== test_notice.py outline =="
ast-grep outline src/Products/urban/services/tests/test_notice.py --view expanded || true

echo
echo "== relevant source lines =="
cat -n src/Products/urban/services/notice.py | sed -n '120,160p'

echo
echo "== relevant test file =="
cat -n src/Products/urban/services/tests/test_notice.py

Repository: IMIO/Products.urban

Length of output: 6268


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== search for notices-related tests =="
rg -n -C2 'notices|notice|get_notifications|_get_notifications' src/Products/urban/services/tests

echo
echo "== search for missing-key or empty-path assertions =="
rg -n -C2 'KeyError|[]|None|empty|missing' src/Products/urban/services/tests/test_notice.py

Repository: IMIO/Products.urban

Length of output: 50375


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
p = Path('src/Products/urban/services/notice.py')
text = p.read_text()
for i, line in enumerate(text.splitlines(), 1):
    if 'notices_obj' in line or 'notices_list' in line or 'return notices_list' in line:
        start = max(1, i-8)
        end = min(len(text.splitlines()), i+8)
        print(f'-- lines {start}-{end} --')
        for j, l in enumerate(text.splitlines()[start-1:end], start):
            print(f'{j:4d}: {l}')
        print()
PY

Repository: IMIO/Products.urban

Length of output: 2752


Add coverage for the empty notices response

src/Products/urban/services/tests/test_notice.py only exercises the populated response path. Add a case where notices/notice is missing and assert get_notifications() returns [] instead of failing on a missing key.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Products/urban/services/notice.py` around lines 138 - 140, The tests for
get_notifications() lack coverage for responses missing notices or notice. Add a
test case in test_notice.py with an empty or incomplete response and assert
get_notifications() returns [] without raising an error.

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