fix: Wochenkalender-Filter und per-Kalender Fehlerbehandlung
Der Wochenkalender von Google hat locale-spezifische IDs (z.B. de.german#weeknum@...) die nicht im alten exakten Set-Filter gefangen wurden. Dadurch wurde er in die DB gespeichert und verursachte beim Event-Abruf einen API-Fehler. Da der try/except die gesamte Kalender-Schleife umschloss, wurden bei einem einzigen fehlerhaften Kalender alle anderen Events ebenfalls verloren — Ursache für keine Termine trotz korrektem Token. - _is_system_calendar(): prüft jetzt auch 'weeknum' als Substring - _sync_google_calendars(): bereinigt bereits gespeicherte System-Kalender - get_google_events(): try/except ist jetzt pro Kalender, nicht global
This commit is contained in:
@@ -32,6 +32,11 @@ SKIP_GOOGLE_CALENDAR_IDS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _is_system_calendar(cal_id: str) -> bool:
|
||||||
|
"""Return True for virtual/system calendars that should be hidden."""
|
||||||
|
return cal_id in SKIP_GOOGLE_CALENDAR_IDS or "weeknum" in cal_id.lower()
|
||||||
|
|
||||||
|
|
||||||
def _google_configured() -> bool:
|
def _google_configured() -> bool:
|
||||||
return bool(GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET)
|
return bool(GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET)
|
||||||
|
|
||||||
@@ -139,7 +144,7 @@ def _account_dict(a: models.GoogleAccount) -> dict:
|
|||||||
"sidebar_hidden": bool(c.sidebar_hidden),
|
"sidebar_hidden": bool(c.sidebar_hidden),
|
||||||
}
|
}
|
||||||
for c in a.calendars
|
for c in a.calendars
|
||||||
if c.cal_id not in SKIP_GOOGLE_CALENDAR_IDS
|
if not _is_system_calendar(c.cal_id)
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,12 +154,16 @@ def _sync_google_calendars(account: models.GoogleAccount, db: Session):
|
|||||||
try:
|
try:
|
||||||
token = _refresh_access_token(account, db)
|
token = _refresh_access_token(account, db)
|
||||||
cal_list = _google_api(token, "/users/me/calendarList")
|
cal_list = _google_api(token, "/users/me/calendarList")
|
||||||
existing = {c.cal_id: c for c in account.calendars}
|
# Remove any previously stored system calendars (e.g. locale-specific weeknum variants)
|
||||||
|
for c in list(account.calendars):
|
||||||
|
if _is_system_calendar(c.cal_id):
|
||||||
|
db.delete(c)
|
||||||
|
existing = {c.cal_id: c for c in account.calendars if not _is_system_calendar(c.cal_id)}
|
||||||
for cal in cal_list.get("items", []):
|
for cal in cal_list.get("items", []):
|
||||||
if cal.get("deleted"):
|
if cal.get("deleted"):
|
||||||
continue
|
continue
|
||||||
cal_id = cal["id"]
|
cal_id = cal["id"]
|
||||||
if cal_id in SKIP_GOOGLE_CALENDAR_IDS:
|
if _is_system_calendar(cal_id):
|
||||||
continue
|
continue
|
||||||
if cal_id not in existing:
|
if cal_id not in existing:
|
||||||
db.add(models.GoogleCalendar(
|
db.add(models.GoogleCalendar(
|
||||||
@@ -378,12 +387,12 @@ def get_google_events(account: models.GoogleAccount, start_dt: datetime, end_dt:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
all_events = []
|
all_events = []
|
||||||
try:
|
|
||||||
for gcal in account.calendars:
|
for gcal in account.calendars:
|
||||||
if not gcal.enabled:
|
if not gcal.enabled:
|
||||||
continue
|
continue
|
||||||
if gcal.cal_id in SKIP_GOOGLE_CALENDAR_IDS:
|
if _is_system_calendar(gcal.cal_id):
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
events_resp = _google_api(token, f"/calendars/{gcal.cal_id}/events", params={
|
events_resp = _google_api(token, f"/calendars/{gcal.cal_id}/events", params={
|
||||||
"timeMin": start_dt.isoformat(),
|
"timeMin": start_dt.isoformat(),
|
||||||
"timeMax": end_dt.isoformat(),
|
"timeMax": end_dt.isoformat(),
|
||||||
@@ -395,7 +404,7 @@ def get_google_events(account: models.GoogleAccount, start_dt: datetime, end_dt:
|
|||||||
continue
|
continue
|
||||||
all_events.append(_parse_google_event(ev, gcal.id, gcal.name, gcal.color or "#4285f4"))
|
all_events.append(_parse_google_event(ev, gcal.id, gcal.name, gcal.color or "#4285f4"))
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Error fetching Google Calendar for %s: %s", account.email, exc)
|
logger.error("Error fetching events for calendar %s (%s): %s", gcal.name, gcal.cal_id, exc)
|
||||||
|
|
||||||
return all_events
|
return all_events
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user