Skip to content

Fix float parsing of ISO section codes like 5.10#799

Merged
northdpole merged 4 commits into
OWASP:mainfrom
VivekGhantiwala:fix/iso-section-float-parsing
Jun 12, 2026
Merged

Fix float parsing of ISO section codes like 5.10#799
northdpole merged 4 commits into
OWASP:mainfrom
VivekGhantiwala:fix/iso-section-float-parsing

Conversation

@VivekGhantiwala

Copy link
Copy Markdown
Contributor

What

Replace get_all_records() with get_all_values() in read_spreadsheet() to prevent gspread's numericise() from
converting ISO section codes like "5.10" to float 5.1.

Why

get_all_records() internally calls numericise() which strips trailing zeros from decimal-looking strings. The
existing numericise_ignore workaround misses column 0 and depends on gspread internals that have known bugs (see gspread#1007).
get_all_values() always returns raw cell strings, so "5.10" stays "5.10". We manually construct the row dicts using
the header row.

Testing

Existing test test_read_spreadsheet_iso_numbers validates that section IDs "1.10" and "10.10" are preserved as
strings.

Closes #574
Closes #546

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@northdpole, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 6 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f690c39f-3332-4c6b-a7cd-2411f828b2c8

📥 Commits

Reviewing files that changed from the base of the PR and between 72ba506 and 9ff4146.

📒 Files selected for processing (2)
  • application/tests/spreadsheet_test.py
  • application/utils/spreadsheet.py

Walkthrough

The PR replaces gspread's automatic numeric conversion in read_spreadsheet with a custom helper function (_records_from_worksheet_values) that builds row dictionaries while preserving string formats like ISO control codes "5.10". The existing test is updated to reflect the new get_all_values() approach, and two new tests verify behavior for empty worksheets and row padding.

Changes

Spreadsheet numericise fix and test coverage

Layer / File(s) Summary
Helper function and read_spreadsheet integration
application/utils/spreadsheet.py
Added _records_from_worksheet_values(rows) to build row dictionaries from raw worksheet values using the first row as headers and padding short rows to match header width. Updated read_spreadsheet to use wsh.get_all_values() with the helper instead of wsh.get_all_records(..., numericise_ignore=...).
Test updates and new edge-case tests
application/tests/spreadsheet_test.py
Updated test_read_spreadsheet_iso_numbers fixture to mock via get_all_values(). Added test_read_spreadsheet_empty_worksheet to verify empty worksheets return empty lists, and test_read_spreadsheet_short_row_padded to verify rows are padded with empty strings for missing columns.

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main fix: preventing float parsing of ISO codes like 5.10, which directly aligns with the core changeset purpose.
Description check ✅ Passed The description is directly related to the changeset, explaining the what, why, and testing approach for replacing get_all_records() with get_all_values().
Linked Issues check ✅ Passed The PR successfully addresses both linked issues by replacing get_all_records() with get_all_values() to preserve ISO codes as strings, preventing conversion of values like 5.10 to 5.1.
Out of Scope Changes check ✅ Passed All changes directly support the core objective: the spreadsheet utility is refactored to preserve ISO codes, and tests are updated/added to validate this behavior.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@northdpole
northdpole force-pushed the fix/iso-section-float-parsing branch from 9d6c10d to e8d7c3e Compare June 12, 2026 10:11
VivekGhantiwala and others added 3 commits June 12, 2026 13:21
Replace get_all_records() with get_all_values() to bypass gspread's
numericise() which converts section codes like '5.10' to float 5.1.
get_all_values() returns raw strings, preserving trailing zeros.

Fixes OWASP#574
Fixes OWASP#546
Align spreadsheet_test with get_all_values-based read path so section
codes like 5.10 stay strings instead of being float-coerced.

Co-authored-by: Cursor <cursoragent@cursor.com>
Handle empty worksheets and pad short rows so section IDs are preserved
as strings without IndexError or truncated dict keys.
@northdpole
northdpole force-pushed the fix/iso-section-float-parsing branch from e8d7c3e to 72ba506 Compare June 12, 2026 10:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@application/utils/spreadsheet.py`:
- Around line 33-37: The code currently builds dicts from headers allowing
duplicate header names to silently collapse columns; update the logic in the
block that defines headers and records to detect duplicate header names (e.g.,
by comparing len(headers) vs len(set(headers))) and immediately raise a clear
exception (ValueError or the same error type used by read_spreadsheet()) when
duplicates are found so the existing read_spreadsheet() duplicate-header failure
path is triggered instead of producing corrupt records; do this check before the
loop that pads rows and constructs records.
- Line 37: Replace the non-strict zip call used when building row dicts so it
raises on length mismatches: update the call inside
records.append(dict(zip(headers, padded[: len(headers)]))) to pass strict=True
to zip (i.e., use headers and the sliced padded sequence with strict=True) so
Ruff B905 is satisfied; locate the expression in the same context where records,
headers, and padded are used and apply the change.
🪄 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: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 616d00a9-f2a8-4421-8e38-fa9b57fcafd9

📥 Commits

Reviewing files that changed from the base of the PR and between 37417e5 and 72ba506.

📒 Files selected for processing (2)
  • application/tests/spreadsheet_test.py
  • application/utils/spreadsheet.py

Comment thread application/utils/spreadsheet.py Outdated
Comment thread application/utils/spreadsheet.py Outdated
Fail fast with GSpreadException when worksheet header row contains
duplicates, use zip(strict=True) after row padding, and add regression
tests for the helper and read_spreadsheet integration.
@northdpole
northdpole merged commit 294b17e into OWASP:main Jun 12, 2026
6 checks passed
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.

Regression of ISO 5.10 issue ISO control numbers interpreted wrongfully

2 participants