Repository navigation
fix(connectors): enforce WebDAV numeric string size limits - #15731
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds 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. ChangesWebDAV size limit implementation and testing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
common/data_source/webdav_connector.pytest/unit_test/data_source/test_webdav_connector_unit.py
3623277 to
e01564f
Compare
|
Hi @Haruko386 @JinHai-CN mind reviewing when you have a moment? Ty |
e01564f to
fc8141c
Compare
DeepeshAlwani
left a comment
There was a problem hiding this comment.
Thanks for addressing the suggestions. The warning on missing metadata and the consistent log level both look good. LGTM.
|
been tryting these changes... now i pretty much get 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/ which properly returns for every file a size getcontentlength fields. something is still wrong here |
|
Thanks for testing and sharing the logs — this actually points to another gap in The method only checks 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. |
|
this seems to work, thank you |
|
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]>
@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. |
Summary
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 -quvx ruff check common/data_source/webdav_connector.py test/unit_test/data_source/test_webdav_connector_unit.pypython -m compileall -q common/data_source/webdav_connector.py test/unit_test/data_source/test_webdav_connector_unit.pygit diff --check