mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-22 16:36:47 +08:00
Fix: table parser metadata (#15127)
### What problem does this PR solve? This PR improves the table upload flow for CSV/Excel files by allowing table column role configuration at upload time. Previously, users had to: 1. Upload and parse a table file. 2. Open parser settings and manually set table column roles. 3. Re-parse the file for the roles to take effect. This was inefficient and required an unnecessary second parse. With this change: 1. When the knowledge base uses table parsing, the upload dialog extracts CSV/Excel headers client-side. 2. Users can choose Auto mode or Manual mode. 3. In Manual mode, users can assign per-column roles before upload. 4. The selected parser config is sent with the upload request and applied server-side during document creation. Result: configured table column roles are applied from the first parse. ### Type of change - [x] New Feature (non-breaking change which adds functionality) Co-authored-by: Ahmad Intisar <ahmadintisar@Ahmads-MacBook-M4-Pro.local>
This commit is contained in:
@@ -585,9 +585,25 @@ async def _upload_local_documents(kb, tenant_id):
|
||||
logging.error(msg)
|
||||
return get_error_data_result(message=msg, code=RetCode.ARGUMENT_ERROR)
|
||||
|
||||
# Parse optional parser_config overrides from form data
|
||||
parser_config_override = None
|
||||
raw_parser_config = form.get("parser_config")
|
||||
if raw_parser_config:
|
||||
try:
|
||||
parsed = json.loads(raw_parser_config)
|
||||
if isinstance(parsed, dict):
|
||||
# Only allow known table column config keys to prevent arbitrary overrides
|
||||
allowed_keys = {"table_column_mode", "table_column_roles"}
|
||||
parser_config_override = {k: v for k, v in parsed.items() if k in allowed_keys}
|
||||
if not parser_config_override:
|
||||
parser_config_override = None
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
parser_config_override = None
|
||||
|
||||
err, files = await thread_pool_exec(
|
||||
FileService.upload_document, kb, file_objs, tenant_id,
|
||||
parent_path=form.get("parent_path")
|
||||
parent_path=form.get("parent_path"),
|
||||
parser_config_override=parser_config_override,
|
||||
)
|
||||
if err:
|
||||
msg = "\n".join(err)
|
||||
|
||||
Reference in New Issue
Block a user