Repository navigation
Custom the file extension when saving DB fields, and Parse HTML fragments not just full HTML doc - #15998
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe RDBMS connector now supports a configurable file extension. Sync configuration passes the value to document generation. MySQL and PostgreSQL settings expose the option with ChangesConfigurable RDBMS file extension
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change adds configurable RDBMS document file extensions with a .txt fallback and related interface text. No concrete merge-blocking risk is currently identified. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant User
participant DataSourceForm
participant SyncDataSource
participant RDBMSConnector
participant Document
User->>DataSourceForm: Set file_extension
DataSourceForm->>SyncDataSource: Save data source configuration
SyncDataSource->>RDBMSConnector: Pass file_extension
RDBMSConnector->>Document: Create document with configured extension
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. A rabbit taps the extension field Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
common/data_source/rdbms_connector.py (1)
56-85:⚠️ Potential issue | 🟠 Major | ⚡ Quick winValidate and normalize
file_extensionbefore persisting it.Line 84 accepts arbitrary config input and forwards it to Line 340 unchanged. Since the persisted schema stores extension-like fields with a 32-char limit, invalid/oversized values can break writes or downstream parser/type routing. Normalize (
strip, ensure leading.) and validate (allowed charset + max length) once in the constructor.Suggested fix
+import re ... - self.file_extension = file_extension if file_extension else '.txt' + self.file_extension = self._normalize_file_extension(file_extension) ... + `@staticmethod` + def _normalize_file_extension(file_extension: Any) -> str: + if file_extension is None: + return ".txt" + if not isinstance(file_extension, str): + raise ConnectorValidationError("file_extension must be a string.") + + ext = file_extension.strip().lower() + if not ext: + return ".txt" + if not ext.startswith("."): + ext = f".{ext}" + if len(ext) > 32: + raise ConnectorValidationError("file_extension must be <= 32 characters.") + if not re.fullmatch(r"\.[a-z0-9]+", ext): + raise ConnectorValidationError( + "file_extension must contain only letters/numbers after '.'." + ) + return extAlso applies to: 340-340
🤖 Prompt for 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. In `@common/data_source/rdbms_connector.py` around lines 56 - 85, The file_extension parameter in the RDBMSConnector constructor is accepted without validation or normalization, which can cause issues downstream since the persisted schema has a 32-character limit on this field. In the __init__ method where self.file_extension is set around line 84, add validation and normalization logic: strip whitespace from the file_extension input, ensure it has a leading dot, validate the character set is appropriate for file extensions, and enforce a maximum length of 32 characters. If the input is invalid or exceeds the limit, raise an appropriate exception with a descriptive message. This ensures only valid, normalized extensions are persisted and prevents downstream parser or type routing issues.
🤖 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 `@web/src/locales/en.ts`:
- Around line 1360-1361: The tooltip strings in the en.ts file are using title
case when they should follow the sentence case convention (first word
capitalized, rest lowercase). Update the mysqlFileExtensionTip entry to use
sentence case: change "The File Extension to save the Content column into files.
default: .txt" to "File extension to save the content column into files.
Default: .txt". Also apply the same sentence case correction to the similar
tooltip entry at lines 1374-1375 to ensure consistency with the en.ts coding
guidelines.
In `@web/src/pages/user-setting/data-source/constant/index.tsx`:
- Around line 1016-1023: Fix the spelling error in both field label definitions
in web/src/pages/user-setting/data-source/constant/index.tsx. At lines 1016-1023
in the MySQL field configuration object, change the label property from "File
Extenstion" to "File Extension". At lines 1098-1105 in the PostgreSQL field
configuration object, change the label property from "File Extenstion" to "File
Extension". Both occurrences use the same misspelled text in their label fields
and require the same correction.
---
Outside diff comments:
In `@common/data_source/rdbms_connector.py`:
- Around line 56-85: The file_extension parameter in the RDBMSConnector
constructor is accepted without validation or normalization, which can cause
issues downstream since the persisted schema has a 32-character limit on this
field. In the __init__ method where self.file_extension is set around line 84,
add validation and normalization logic: strip whitespace from the file_extension
input, ensure it has a leading dot, validate the character set is appropriate
for file extensions, and enforce a maximum length of 32 characters. If the input
is invalid or exceeds the limit, raise an appropriate exception with a
descriptive message. This ensures only valid, normalized extensions are
persisted and prevents downstream parser or type routing issues.
🪄 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: dadf011d-f152-4acf-86d2-287ab7b4ac54
📒 Files selected for processing (5)
common/data_source/rdbms_connector.pydeepdoc/parser/html_parser.pyrag/svr/sync_data_source.pyweb/src/locales/en.tsweb/src/pages/user-setting/data-source/constant/index.tsx
2d50bc8 to
53c0428
Compare
|
@wadefelix would you please fix the conflicts? |
53c0428 to
9f6f65d
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
9f6f65d to
6dd5d14
Compare
done |
| { | ||
| label: 'File Extension', | ||
| name: 'config.file_extension', | ||
| type: FormFieldType.Text, | ||
| required: false, | ||
| placeholder: '.txt', | ||
| tooltip: t('setting.postgresqlFileExtensionTip'), | ||
| }, |
There was a problem hiding this comment.
Since each DB row is synced as a single file with a single extension,
while HTML/Markdown content usually lives in specific columns, the option only works correctly when users select only the pure HTML/Markdown columns in "content columns". Could you update the tooltip to make this clear? Proposed copy:
The extension used for documents synced from this source (default: .txt). Since each row is saved as one file, when set to .html or .md, select only content columns that are purely HTML or Markdown.
(applies to both mysqlFileExtensionTip and postgresqlFileExtensionTip)
|
And please fix the ruff formatting issue. |
|
另外,解析html时要兼容解析html片段(无body标签),而不是仅仅支持完整的html文档(有body标签)
69058f4 to
6eccac9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15998 +/- ##
==========================================
+ Coverage 29.85% 37.83% +7.98%
==========================================
Files 54 54
Lines 15343 15354 +11
Branches 118 119 +1
==========================================
+ Hits 4580 5809 +1229
+ Misses 10751 9519 -1232
- Partials 12 26 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
Briefly describe what this PR aims to solve. Include background context that will help reviewers understand the purpose of the PR.
Since the database fields often store HTML fragments or Markdown fragments, a custom file name suffix field was added in the database datasource. Also, when parsing HTML, it should be compatible with parsing HTML fragments (without a body tag), not just full HTML documents (with a body tag).
Type of change