feat: enhance MediaWiki integration and error handling in SMW client
- Added MediaWiki API configuration options to docker-compose.yml for production environment. - Improved error handling in the SMW client by introducing a response parsing method to manage API errors more effectively. - Updated methods in the SMW client to ensure robust handling of API responses, preventing potential crashes due to unexpected data structures. - Enhanced the import functionality to handle last imported timestamps more gracefully.
This commit is contained in:
1 parent
07b1cd8209
commit
362eb4145f
3 files changed
+71
-26
No files matched your search
@@ -120,7 +120,9 @@ async def preview_import(
|
||||
"wiki_page_title": page_title,
|
||||
"wiki_page_id": page_id,
|
||||
"already_imported": existing_ref is not None,
|
||||
"last_imported_at": existing_ref["last_imported"].isoformat() if existing_ref else None,
|
||||
"last_imported_at": existing_ref["last_imported"].isoformat()
|
||||
if existing_ref and existing_ref.get("last_imported") is not None
|
||||
else None,
|
||||
"mapped_fields": mapped_fields,
|
||||
"warnings": warnings,
|
||||
"errors": errors,
|
||||
@@ -639,21 +641,38 @@ def _upsert_skill(mapped: dict, reimport: bool) -> Optional[int]:
|
||||
return skill_id
|
||||
|
||||
|
||||
def _upsert_method(mapped: dict, reimport: bool) -> Optional[int]:
|
||||
"""Legt Trainingsmethode an oder aktualisiert Beschreibung."""
|
||||
def _upsert_method(mapped: dict, _reimport: bool) -> Optional[int]:
|
||||
"""Legt Trainingsmethode an oder aktualisiert Beschreibung nach Namen.
|
||||
|
||||
training_methods.name hat keinen UNIQUE-Constraint — daher kein ON CONFLICT (name).
|
||||
"""
|
||||
name = (mapped.get("name") or "").strip()
|
||||
desc = mapped.get("description")
|
||||
if not name:
|
||||
return None
|
||||
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"""INSERT INTO training_methods (name, description)
|
||||
VALUES (%s, %s)
|
||||
ON CONFLICT (name) DO UPDATE SET
|
||||
description = EXCLUDED.description
|
||||
RETURNING id""",
|
||||
(mapped["name"], mapped.get("description"))
|
||||
"SELECT id FROM training_methods WHERE TRIM(name) ILIKE TRIM(%s)",
|
||||
(name,),
|
||||
)
|
||||
method_id = cur.fetchone()['id']
|
||||
row = cur.fetchone()
|
||||
if row:
|
||||
mid = row["id"]
|
||||
cur.execute(
|
||||
"UPDATE training_methods SET description = %s, updated_at = NOW() WHERE id = %s",
|
||||
(desc, mid),
|
||||
)
|
||||
conn.commit()
|
||||
return mid
|
||||
cur.execute(
|
||||
"INSERT INTO training_methods (name, description) VALUES (%s, %s) RETURNING id",
|
||||
(name, desc),
|
||||
)
|
||||
mid = cur.fetchone()["id"]
|
||||
conn.commit()
|
||||
return method_id
|
||||
return mid
|
||||
|
||||
|
||||
def _upsert_wiki_ref(
|
||||
|
||||
Reference in new issue
Block a user