Skip to content

fix(open-meteo): guard forecast sequence bounds and prevent null-unit concatenation TypeError - #13923

Merged
kodjima33 merged 2 commits into
BasedHardware:mainfrom
Ivansky1:fix/open-meteo-forecast-bounds-and-null-units
Sep 15, 2026
Merged

kodjima33 merged 2 commits into
BasedHardware:mainfrom
Ivansky1:fix/open-meteo-forecast-bounds-and-null-units

Conversation

@Ivansky1

@Ivansky1 Ivansky1 commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

In plugins/omi-open-meteo-app/main.py:

  1. Forecast Array Bounds & IndexError Prevention: In get_weather_forecast, daily metric lists were accessed via (daily.get("weather_code") or [None])[index]. If any daily array is empty or shorter than daily["time"], indexing beyond element 0 raises an unhandled IndexError: list index out of range, failing the entire user forecast request. Added _safe_item helper to safely index sequences and fall back to "n/a" / "unknown".
  2. Null Unit String Concatenation TypeError Prevention: In get_current_weather, get_weather_forecast, and get_air_quality, expressions such as ' ' + units.get(...) crash with TypeError: can only concatenate str (not "NoneType") to str when the units payload contains null values in JSON. Implemented _format_unit_suffix to safely handle non-null string units.
  3. Empty Forecast Result Handling: If daily["time"] is empty or missing, returns an explicit No forecast data available for {place_name}. instead of a blank header.
  4. Hermetic Test Suite: Added plugins/omi-open-meteo-app/test_main.py with 8 comprehensive unit tests covering partial daily arrays, null units, and empty time scenarios. Registered open-meteo-app-tests in .github/checks-manifest.yaml.

Testing

  • python plugins/omi-open-meteo-app/test_main.py: All 8 tests pass.
  • python plugins/omi-open-meteo-app/test_observed_at.py: All tests pass.
  • git diff --check origin/main: 0 whitespace or formatting warnings.

Bounty Payout Destination (EVM / Base USDC): 0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0
cc @josancamon19 @kodjima33

Review in cubic

… concatenation TypeError

1. In get_weather_forecast, accessing daily metric arrays with (daily.get('weather_code') or [None])[index] raised IndexError whenever arrays were empty or shorter than time, failing the entire forecast request. Replaced with safe _safe_item extraction, gracefully falling back to 'n/a' or 'unknown' per field.
2. In get_current_weather, get_weather_forecast, and get_air_quality, unit suffix concatenation like ' ' + units.get(...) raised TypeError if the API or proxy returned null unit values in JSON. Added _format_unit_suffix to safely format non-null string units.
3. If daily['time'] is empty or missing, returns an informative message rather than an empty header.
4. Hardened _format_number to treat booleans as non-numeric ('n/a').
5. Added comprehensive hermetic unit tests in plugins/omi-open-meteo-app/test_main.py and registered open-meteo-app-tests in .github/checks-manifest.yaml.

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 4 files

You’re at about 96% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread plugins/omi-open-meteo-app/test_main.py Resolved
Comment thread plugins/omi-open-meteo-app/test_main.py Resolved
@Ivansky1

Copy link
Copy Markdown
Contributor Author

Addressed static review feedback in commit e1aee39:

  • Set \PLUGIN_DIR = Path(file).resolve().parent\ so the plugin root is correctly resolved relative to the test location.
  • Added standard-library fallbacks/stubs for \ astapi, \httpx, and \pydantic\ when run in clean CI runner environments without third-party dependencies. Tested hermetically with clean Python stdlib (8/8 tests passing).

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution python labels Sep 15, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Reviewed the Open-Meteo hardening fix end to end — the three crash paths it guards against are real on main, the fix is minimal and correct, and I ran the new suite in a clean, network-isolated Python 3.12 container: 8/8 tests pass.

Per file:

  • plugins/omi-open-meteo-app/main.py — The old forecast loop indexed daily arrays directly, e.g. (daily.get("weather_code") or [None])[index], so any metric array shorter than daily.time raised IndexError and failed the whole request; _safe_item with a None default flowing into the existing n/a formatting is the right shape. The ' ' + units.get("wind_speed_10m_max", "") pattern crashed with TypeError whenever the API returned a null unit — replacing it with _format_unit_suffix (and str(... or "") elsewhere) fixes all three endpoints; the % default for precipitation probability is correctly preserved. Hardening _format_number against bool values and null suffixes is a sensible bonus. Output for well-formed payloads is unchanged.
  • plugins/omi-open-meteo-app/test_main.py — Good hermetic suite: the stub modules for httpx/fastapi/pydantic are inert (no network, no filesystem access), and the endpoint tests exercise exactly the partial-array, null-unit, and empty-time scenarios via AsyncMock patches of _resolve_location/_request_json. All 8 tests pass on a clean stdlib-only Python.
  • .github/checks-manifest.yaml — The new open-meteo-app-tests entry follows the existing omi-linear-app pattern and satisfies the manifest validation rules (non-empty triggers, both local+ci lanes, non-empty reason).
  • plugins/omi-open-meteo-app/test_observed_at.py — The sys.path insertion and main runner are fine. One minor note: unlike test_main.py, this script has no dependency stubs, so python3 test_observed_at.py still fails on a clean stdlib env because main.py imports httpx at module scope. Non-blocking since the manifest runs only test_main.py — worth a follow-up if you ever want it runnable standalone.

Thanks for the clean fix and the tests — nice first contribution. Since no CI run has reported on this head yet, leaving final merge sign-off to a human maintainer.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Real bug confirmed not fixed on main (plugins/omi-open-meteo-app/main.py has no _safe_item/_format_unit_suffix guards; indexing daily arrays out of bounds and concatenating null units both still crash). Root cause stated, 8 new hermetic tests plus existing test_observed_at.py updated, scoped diff. Merging: CI has no failing required checks, not a draft, no abuse signals.

@Ivansky1

Copy link
Copy Markdown
Contributor Author

Note for bounty payout: Please route the .00 USDC payout to my verified EVM / Base self-custody wallet:

@Ivansky1

Copy link
Copy Markdown
Contributor Author

Payout information update:

  • PayPal: [email protected]
  • Base / EVM (USDC): 0xb5aFc89b57Fa8270bB7261348179D28099BEa2a0

Thank you!

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

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants