Skip to content

fix(connectors): enforce WebDAV numeric string size limits - #15731

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
oktofeesh1:codex/webdav-size-metadata
Jun 11, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
oktofeesh1:codex/webdav-size-metadata

Conversation

@oktofeesh1

Copy link
Copy Markdown
Contributor

Summary

  • Normalize WebDAV file-size metadata before applying the sync size threshold.
  • Enforce the same threshold for numeric string sizes in both document sync and slim snapshot paths.
  • Add focused WebDAV unit coverage for size parsing and over-threshold skips.

Why

Some WebDAV servers return file sizes from PROPFIND metadata as strings. The previous threshold check only handled integer values, so oversized files could still be downloaded and sent into the chunking pipeline.

Closes #15724.

Validation

  • uv run --no-project --with pytest --with pytest-asyncio pytest test/unit_test/data_source/test_webdav_connector_unit.py -q
  • uvx ruff check common/data_source/webdav_connector.py test/unit_test/data_source/test_webdav_connector_unit.py
  • python -m compileall -q common/data_source/webdav_connector.py test/unit_test/data_source/test_webdav_connector_unit.py
  • git diff --check

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 308b3c03-8b14-494b-bb0c-d64acd2d0645

📥 Commits

Reviewing files that changed from the base of the PR and between fc8141c and 60cc370.

📒 Files selected for processing (2)
  • common/data_source/webdav_connector.py
  • test/unit_test/data_source/test_webdav_connector_unit.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • common/data_source/webdav_connector.py
  • test/unit_test/data_source/test_webdav_connector_unit.py

📝 Walkthrough

Walkthrough

Adds strict WebDAV size parsing and stable log identifiers; enforces size_threshold by skipping items whose parsed size is missing or exceeds the threshold; preserves true zero sizes. Includes isolated unit tests that dynamically load the connector and validate parsing and skip/warning behavior.

Changes

WebDAV size limit implementation and testing

Layer / File(s) Summary
Size validation helper and connector integration
common/data_source/webdav_connector.py
Adds urlsplit import, _get_size_bytes() to parse/validate WebDAV size into `int
Comprehensive unit test suite (isolated load)
test/unit_test/data_source/test_webdav_connector_unit.py
Adds isolated test harness that stubs common.data_source.* and webdav4.client in sys.modules, dynamically loads the connector, tests _get_size_bytes() parsing (valid integers and numeric strings; rejects empty, non-numeric, negative, boolean, overly-large), and verifies size-threshold filtering in _yield_webdav_documents() and retrieve_all_slim_docs_perm_sync() including download skip behavior and warning logs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I hop through sizes, sniffing bytes so small,
I skip the giants, and I log them all.
A tidy helper counts each numeric clue,
Leaves zeros true, and tests peek through.
Little paws applaud the careful crawl.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description includes a Summary section, Why section with context, and Validation instructions, but lacks the structured template with the 'What problem does this PR solve?' and 'Type of change' checklist sections. Restructure the description to follow the repository template: add explicit 'What problem does this PR solve?' section and include the Type of change checklist with appropriate items selected.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: enforcing WebDAV numeric string size limits, which directly addresses the core issue of WebDAV servers returning file sizes as strings.
Linked Issues check ✅ Passed The PR implementation directly addresses all coding requirements from issue #15724: normalizing WebDAV size metadata, enforcing size thresholds for numeric strings, adding unit test coverage for size parsing, and handling multiple key variations (size, content_length, getcontentlength).
Out of Scope Changes check ✅ Passed All changes are scope-appropriate: WebDAV connector size normalization, threshold logic updates, and focused unit test coverage for size validation—all directly addressing the oversized file bypass issue.

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


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.

@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: 4

🤖 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 `@common/data_source/webdav_connector.py`:
- Around line 385-391: Add a debug log before the continue in the size-threshold
branch so skips are visible; specifically, when size_bytes (from
self._get_size_bytes(file_info)) exceeds self.size_threshold, log via
self.logger.debug a concise message including the file identifier from file_info
(e.g., name or href), the computed size_bytes and the configured
self.size_threshold, then continue. Ensure the log uses the same logger
convention as other methods (e.g., self.logger.debug) and mirrors the format
used in _yield_webdav_documents() for consistency.
- Around line 68-69: In _get_size_bytes, the current branch returns any int
including negatives; change the check so only non-negative integers are
accepted: in the isinstance(size_bytes, int) branch verify size_bytes >= 0 (and
exclude bool if necessary) and return the value only when non-negative,
otherwise return None to match the normalization for string inputs; update the
method _get_size_bytes accordingly.

In `@test/unit_test/data_source/test_webdav_connector_unit.py`:
- Around line 98-109: The test patches sys.modules with stub modules "webdav4"
and "webdav4.client" but never restores them, causing test leakage; update the
test in test_webdav_connector_unit.py to save originals (e.g., orig_webdav4 =
sys.modules.get("webdav4") and orig_webdav4_client =
sys.modules.get("webdav4.client")) before assigning the ModuleType stubs and
restore them after the isolated import (in a finally block or teardown) by
setting sys.modules["webdav4"] = orig_webdav4 (or deleting the key if None) and
similarly for "webdav4.client"; apply the same save/restore pattern to the other
occurrence mentioned (lines ~130-137).
- Around line 159-216: Add the required pytest priority markers to the new tests
by importing pytest and decorating each test function with the appropriate
marker (e.g. `@pytest.mark.p1` or p2/p3 per the test's priority). Specifically,
add markers to test_get_size_bytes_accepts_integer_strings,
test_get_size_bytes_ignores_unknown_values,
test_yield_webdav_documents_skips_numeric_string_sizes_over_threshold, and
test_retrieve_all_slim_docs_skips_numeric_string_sizes_over_threshold in the
WebDAVConnector unit test file so they comply with the project guideline
requiring pytest priority markers for test/**/*.py.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6da4d13f-627b-4235-a224-28f1efc66cac

📥 Commits

Reviewing files that changed from the base of the PR and between 5a04ac0 and 3623277.

📒 Files selected for processing (2)
  • common/data_source/webdav_connector.py
  • test/unit_test/data_source/test_webdav_connector_unit.py

Comment thread common/data_source/webdav_connector.py Resolved
Comment thread common/data_source/webdav_connector.py Resolved
@oktofeesh1
oktofeesh1 force-pushed the codex/webdav-size-metadata branch from 3623277 to e01564f Compare June 7, 2026 09:51
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 7, 2026
@oktofeesh1

Copy link
Copy Markdown
Contributor Author

Hi @Haruko386 @JinHai-CN mind reviewing when you have a moment? Ty

Comment thread common/data_source/webdav_connector.py Resolved
@oktofeesh1
oktofeesh1 force-pushed the codex/webdav-size-metadata branch from e01564f to fc8141c Compare June 7, 2026 16:02
@oktofeesh1
oktofeesh1 requested a review from DeepeshAlwani June 8, 2026 06:59

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

Thanks for addressing the suggestions. The warning on missing metadata and the consistent log level both look good. LGTM.

@rejuce

rejuce commented Jun 9, 2026 •

Copy link
Copy Markdown

been tryting these changes...

now i pretty much get
2026-06-09 21:33:39,055 WARNING 40 Rahmenauft\xe4ge.xlsx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 ~$ad ring.pdf: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 ~$justment Measuringhead CCI2D.pdf: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 ~$nstellung MK CCI2D.pdf: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 ~$rtungseinheit FDM20.pdf: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 Reparaturbericht_IDS25_140_Modul_2020_02_03_VS-3762.docx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 Reparaturbericht_Systemeinheit_2021_10_26_2S-0342.docx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 Reparaturbericht_Systemeinheit_2021_10_26_2S-0342.pdf: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 Reparaturbericht_Trigger_2020_04_14_VS-0087.docx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,055 WARNING 40 Traversen_PC-rep.und mod. .xlsx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

2026-06-09 21:33:39,056 WARNING 40 Resturlaubsplanung 2020.xlsx: size metadata missing from WebDAV server response, skipping to avoid processing potentially large files.

on every file...

i used curl request on my webdav server

curl -i -X PROPFIND http://localhost:8081/
-H "Depth: 1"
--user webdav:webdavpassword
HTTP/1.1 207 Multi-Status
Accept-Ranges: bytes

which properly returns for every file a size
<D:href>/gitea-dump-1601383580.zip</D:href>
...
<D:getcontentlength>29235489</D:getcontentlength>
<D:href>/logo.png</D:href>
...
<D:getcontentlength>12880</D:getcontentlength>

getcontentlength fields. something is still wrong here

@DeepeshAlwani

Copy link
Copy Markdown

Thanks for testing and sharing the logs — this actually points to another gap in _get_size_bytes.

The method only checks file_info.get("size"), but webdav4's ls(detail=True) doesn't always map getcontentlength to "size" — depending on the server and library version it may return it under "content_length" or "getcontentlength" instead. So even though your server is correctly returning size in the PROPFIND response, file_info.get("size") comes back None for every file, triggering the missing metadata warning on everything.

The fix would be to check multiple possible keys:

size_bytes = (
    file_info.get("size")
    or file_info.get("content_length")
    or file_info.get("getcontentlength")
)

This would make the check resilient across different WebDAV server implementations without changing any other behavior. Happy to put up a follow-up PR for this if the maintainers agree.


Note: findings are my own, used AI assistance only to improve grammar and structure.

@rejuce

rejuce commented Jun 9, 2026

Copy link
Copy Markdown

this seems to work, thank you

@DeepeshAlwani

Copy link
Copy Markdown

Happy to open a follow-up PR with this fix if preferred rather than updating this one.

webdav4's Client.ls(detail=True) reports a file's size under
"content_length" (webdav4.multistatus.Response.as_dict), not "size" —
the "size" key only exists in webdav4's fsspec wrapper, which this
connector does not use. As a result _get_size_bytes always returned
None, the size-threshold guard never fired, and every file tripped the
"size metadata missing" warning.

Source the size from "size", "content_length", and the raw
"getcontentlength" property, using the first key that yields a valid
value so the guard works across server/library variations.

Reported by @DeepeshAlwani on #15731.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@oktofeesh1

Copy link
Copy Markdown
Contributor Author

Happy to open a follow-up PR with this fix if preferred rather than updating this one.

@DeepeshAlwani Great catch — confirmed and pushed. You're right that webdav4's Client.ls(detail=True) reports the size under content_length (webdav4.multistatus.Response.as_dict), not size — the size key only exists in webdav4's fsspec wrapper, which this connector doesn't use. So _get_size_bytes was returning None for every file and the guard never fired. I went with checking size → content_length → getcontentlength (first valid value wins, so zero-byte files and existing servers still work) and added unit tests for the content_length/getcontentlength paths. Thanks for digging into this with the logs.

@wangq8 wangq8 added the ci Continue Integration label Jun 11, 2026
@wangq8
wangq8 merged commit c15b2b3 into infiniflow:main Jun 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration 🌈 python Pull requests that update Python code size:M This PR changes 30-99 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: webdav data source has no file size limit

4 participants