- Problem adding documents
This commit is contained in:
@@ -6,6 +6,7 @@ from flask_security import roles_accepted, current_user
|
||||
from sqlalchemy import desc
|
||||
from sqlalchemy.orm import aliased
|
||||
from werkzeug.utils import secure_filename
|
||||
from werkzeug.datastructures import CombinedMultiDict
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
import requests
|
||||
from requests.exceptions import SSLError, HTTPError
|
||||
@@ -354,7 +355,17 @@ def handle_retriever_selection():
|
||||
@document_bp.route('/add_document', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def add_document():
|
||||
form = AddDocumentForm(request.form)
|
||||
# Log vroege request-info om uploadproblemen te diagnosticeren
|
||||
try:
|
||||
current_app.logger.debug(
|
||||
f"[add_document] method={request.method}, content_type={request.content_type}, "
|
||||
f"files_keys={list(request.files.keys())}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Bind expliciet zowel form- als file-data aan de form (belangrijk voor FileField & CSRF)
|
||||
form = AddDocumentForm(CombinedMultiDict([request.form, request.files]))
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if catalog_id is None:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
@@ -364,6 +375,38 @@ def add_document():
|
||||
if catalog.configuration and len(catalog.configuration) > 0:
|
||||
form.add_dynamic_fields("tagging_fields", catalog.configuration)
|
||||
|
||||
current_app.logger.debug("In Add Document")
|
||||
|
||||
# Extra debug logging om CSRF/payload te controleren
|
||||
try:
|
||||
current_app.logger.debug(
|
||||
f"[add_document] request.form keys: {list(request.form.keys())}"
|
||||
)
|
||||
current_app.logger.debug(
|
||||
f"[add_document] csrf_token in form? {request.form.get('csrf_token') is not None}"
|
||||
)
|
||||
try:
|
||||
has_csrf_field = hasattr(form, 'csrf_token')
|
||||
current_app.logger.debug(
|
||||
f"[add_document] form has csrf field? {has_csrf_field}"
|
||||
)
|
||||
if has_csrf_field:
|
||||
# Let op: we loggen geen tokenwaarde om lekken te vermijden; enkel aanwezigheid
|
||||
current_app.logger.debug(
|
||||
"[add_document] form.csrf_token field is present on form object"
|
||||
)
|
||||
# Bevestig of de CSRF-waarde effectief in de form is gebonden
|
||||
try:
|
||||
current_app.logger.debug(
|
||||
f"[add_document] csrf bound? data_present={bool(form.csrf_token.data)} field_name={getattr(form.csrf_token, 'name', None)}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
current_app.logger.info(f'Adding Document for {catalog_id}')
|
||||
@@ -400,6 +443,25 @@ def add_document():
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'Error adding document: {str(e)}')
|
||||
flash('An error occurred while adding the document.', 'danger')
|
||||
else:
|
||||
# Toon en log validatiefouten als de submit faalt
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
current_app.logger.warning(
|
||||
f"[add_document] form validation failed. errors={getattr(form, 'errors', {})}"
|
||||
)
|
||||
current_app.logger.debug(
|
||||
f"[add_document] request.files keys after validation: {list(request.files.keys())}"
|
||||
)
|
||||
current_app.logger.debug(
|
||||
f"[add_document] request.form keys after validation: {list(request.form.keys())}"
|
||||
)
|
||||
current_app.logger.debug(
|
||||
f"[add_document] csrf_token in form after validation? {request.form.get('csrf_token') is not None}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('document/add_document.html', form=form)
|
||||
|
||||
@@ -407,7 +469,16 @@ def add_document():
|
||||
@document_bp.route('/add_url', methods=['GET', 'POST'])
|
||||
@roles_accepted('Super User', 'Partner Admin', 'Tenant Admin')
|
||||
def add_url():
|
||||
form = AddURLForm(request.form)
|
||||
# Log vroege request-info om submitproblemen te diagnosticeren
|
||||
try:
|
||||
current_app.logger.debug(
|
||||
f"[add_url] method={request.method}, content_type={request.content_type}, files_keys={list(request.files.keys())}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Bind expliciet zowel form- als file-data (consistentie en duidelijkheid)
|
||||
form = AddURLForm(CombinedMultiDict([request.form, request.files]))
|
||||
catalog_id = session.get('catalog_id', None)
|
||||
if catalog_id is None:
|
||||
flash('You need to set a Session Catalog before adding Documents or URLs', 'warning')
|
||||
@@ -417,6 +488,15 @@ def add_url():
|
||||
if catalog.configuration and len(catalog.configuration) > 0:
|
||||
form.add_dynamic_fields("tagging_fields", catalog.configuration)
|
||||
url=""
|
||||
# Kleine debug om te zien of CSRF aan de form gebonden is
|
||||
try:
|
||||
if hasattr(form, 'csrf_token'):
|
||||
current_app.logger.debug(
|
||||
f"[add_url] csrf bound? data_present={bool(form.csrf_token.data)} field_name={getattr(form.csrf_token, 'name', None)}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if form.validate_on_submit():
|
||||
try:
|
||||
tenant_id = session['tenant']['id']
|
||||
@@ -462,6 +542,15 @@ def add_url():
|
||||
except Exception as e:
|
||||
current_app.logger.error(f'Error adding document: {str(e)}')
|
||||
flash('An error occurred while adding the document.', 'danger')
|
||||
else:
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
current_app.logger.warning(
|
||||
f"[add_url] form validation failed. errors={getattr(form, 'errors', {})}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
form_validation_failed(request, form)
|
||||
|
||||
return render_template('document/add_url.html', form=form)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user