Skip to content

fix: suppress xlsxwriter URL warning when writing cells DEV-2020 - #346

Merged
noliveleger merged 3 commits into
mainfrom
dev-2020-suppress-xlsxwriter-url-warning
Jun 17, 2026
Merged

fix: suppress xlsxwriter URL warning when writing cells DEV-2020#346
noliveleger merged 3 commits into
mainfrom
dev-2020-suppress-xlsxwriter-url-warning

Conversation

@noliveleger

@noliveleger noliveleger commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

xlsxwriter emitted a UserWarning when writing a cell containing a URL that exceeds its internal limits (too long or too many URLs in the sheet), even when the code already handles those cases gracefully by falling back to plain-string writing.

Notes

  • warnings.catch_warnings() + filterwarnings('ignore', message='Ignoring URL', ...) wraps each sheet_.write() call in Export._append_row_to_sheet
  • The fallback to write_string() on non-zero return code is unchanged
  • Both test_xlsx_too_many_urls now assert the warning is not raised (via filterwarnings('error', ...))

Preview steps

  • Run pytest tests/test_exports.py::TestFormPackExport::test_xlsx_too_many_urls -m slow — should pass with no warnings
  • Comment lines, the test should not pass

@noliveleger noliveleger self-assigned this Jun 5, 2026
@coveralls

coveralls commented Jun 5, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 86.847% (+0.01%) from 86.834% — dev-2020-suppress-xlsxwriter-url-warning into main

@noliveleger
noliveleger force-pushed the dev-2020-suppress-xlsxwriter-url-warning branch from acaa269 to 6598c57 Compare June 5, 2026 19:55
@noliveleger

Copy link
Copy Markdown
Contributor Author

@greptileai review

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR suppresses xlsxwriter UserWarnings that were emitted for URLs exceeding internal limits, even though the code already handled those cases by falling back to plain-string writing. It moves warnings.catch_warnings() to wrap the entire submission-processing loop in to_xlsx, and adds a filterwarnings('error', ...) guard in test_xlsx_too_many_urls to verify the warning is fully suppressed end-to-end.

  • export.py: Added a single warnings.catch_warnings() context wrapping the entire parse_submissions loop, filtering out 'Ignoring URL' UserWarnings from xlsxwriter — replacing an earlier per-cell approach (flagged in a prior review) with one setup/teardown for the whole export.
  • test_exports.py: Updated test_xlsx_too_many_urls to treat the target warning as an error, so any regression that re-enables it will immediately fail the test.
  • xlsform_parameters.py: Minor cleanup — uses a raw string literal r'\s+' for the regex pattern.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to suppressing a cosmetic warning that was already handled gracefully, and the existing fallback logic is untouched.

The catch_warnings context is now correctly placed at the outermost loop, addressing the previous per-cell overhead concern. The fallback write path and error-handling logic in _append_row_to_sheet are unchanged. The new filterwarnings('error', ...) guard in the test confirms the suppression is effective end-to-end. No functional logic was altered.

No files require special attention.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["to_xlsx(submissions)"] --> B["warnings.catch_warnings()"]
    B --> C["filterwarnings('ignore', 'Ignoring URL', UserWarning, xlsxwriter)"]
    C --> D["for chunk in parse_submissions(submissions)"]
    D --> E["for section_name, rows in chunk.items()"]
    E --> F["resolve/create sheet"]
    F --> G["_append_row_to_sheet(header)"]
    G --> H["for row in rows: _append_row_to_sheet(row)"]
    H --> I{"sheet_.write() return code"}
    I -->|"== 0"| J["Cell written OK"]
    I -->|"!= 0 (URL too long/many)"| K["sheet_.write_string() fallback"]
    K --> L{"write_string return code"}
    L -->|"-1"| M["raise FormPackExcelError"]
    L -->|"-2"| N["Prepend truncation warning, write again"]
    L -->|"0"| O["Cell written as plain string"]
    H --> P["More rows?"]
    P -->|"Yes"| H
    P -->|"No"| Q["workbook.close()"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["to_xlsx(submissions)"] --> B["warnings.catch_warnings()"]
    B --> C["filterwarnings('ignore', 'Ignoring URL', UserWarning, xlsxwriter)"]
    C --> D["for chunk in parse_submissions(submissions)"]
    D --> E["for section_name, rows in chunk.items()"]
    E --> F["resolve/create sheet"]
    F --> G["_append_row_to_sheet(header)"]
    G --> H["for row in rows: _append_row_to_sheet(row)"]
    H --> I{"sheet_.write() return code"}
    I -->|"== 0"| J["Cell written OK"]
    I -->|"!= 0 (URL too long/many)"| K["sheet_.write_string() fallback"]
    K --> L{"write_string return code"}
    L -->|"-1"| M["raise FormPackExcelError"]
    L -->|"-2"| N["Prepend truncation warning, write again"]
    L -->|"0"| O["Cell written as plain string"]
    H --> P["More rows?"]
    P -->|"Yes"| H
    P -->|"No"| Q["workbook.close()"]
Loading

Reviews (4): Last reviewed commit: "tests: fix Python 3.12 SyntaxWarning" | Re-trigger Greptile

Comment thread src/formpack/reporting/export.py Outdated
@rgraber
rgraber self-requested a review June 17, 2026 12:50
@noliveleger
noliveleger force-pushed the dev-2020-suppress-xlsxwriter-url-warning branch from f7521ee to 6b6b60d Compare June 17, 2026 13:02
@noliveleger
noliveleger force-pushed the dev-2020-suppress-xlsxwriter-url-warning branch from def1423 to 7a9c528 Compare June 17, 2026 13:16

@rgraber rgraber 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.

LGTM

@noliveleger
noliveleger merged commit 176f619 into main Jun 17, 2026
6 of 9 checks passed
@noliveleger
noliveleger deleted the dev-2020-suppress-xlsxwriter-url-warning branch June 17, 2026 16:01
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.

3 participants