[PR #344] [MERGED] Fix UnifiedOAuthToken metadata property, import timedelta, and add model tests #310

Closed
opened 2026-03-02 23:35:04 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/AJaySi/ALwrity/pull/344
Author: @AJaySi
Created: 2/11/2026
Status: Merged
Merged: 2/11/2026
Merged by: @AJaySi

Base: mainHead: codex/repair-model-level-defects-for-production


📝 Commits (1)

  • c9b906e Fix unified oauth token metadata and expiry handling

📊 Changes

2 files changed (+84 additions, -9 deletions)

View changed files

📝 backend/models/unified_oauth_tokens.py (+8 -9)
backend/tests/models/test_unified_oauth_tokens.py (+76 -0)

📄 Description

Motivation

  • Repair model-level defects in UnifiedOAuthToken around time calculations and a reserved metadata property to avoid runtime errors in production.
  • Ensure migration/table helper logging is available via a module-level logger to surface migration issues.
  • Add unit tests to validate expiry, refresh detection, and metadata JSON handling to prevent regressions.

Description

  • Imported timedelta from datetime and initialized a module-level loguru logger via from loguru import logger in backend/models/unified_oauth_tokens.py to support needs_refresh computations and logging.
  • Renamed the model property metadata to token_metadata while keeping the backing column metadata_json and implemented JSON serialization/deserialization in the new getter/setter.
  • Updated internal references to use token_metadata (including the details block in to_connection_status) and removed a duplicate local import of logger.
  • Added unit tests at backend/tests/models/test_unified_oauth_tokens.py validating is_expired, needs_refresh, metadata serialization round-trip, and graceful handling of invalid JSON.

Testing

  • Ran the model test file with pytest -q backend/tests/models/test_unified_oauth_tokens.py, which completed with 6 passed and warnings; all tests passed.
  • The tests exercise expiry detection, refresh-buffer logic, metadata set/get round-trip, and invalid-JSON fallback behavior and succeeded.

Codex Task


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/AJaySi/ALwrity/pull/344 **Author:** [@AJaySi](https://github.com/AJaySi) **Created:** 2/11/2026 **Status:** ✅ Merged **Merged:** 2/11/2026 **Merged by:** [@AJaySi](https://github.com/AJaySi) **Base:** `main` ← **Head:** `codex/repair-model-level-defects-for-production` --- ### 📝 Commits (1) - [`c9b906e`](https://github.com/AJaySi/ALwrity/commit/c9b906ecebcf92d87d0a91f604ee16c8ac9e0bb8) Fix unified oauth token metadata and expiry handling ### 📊 Changes **2 files changed** (+84 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `backend/models/unified_oauth_tokens.py` (+8 -9) ➕ `backend/tests/models/test_unified_oauth_tokens.py` (+76 -0) </details> ### 📄 Description ### Motivation - Repair model-level defects in `UnifiedOAuthToken` around time calculations and a reserved `metadata` property to avoid runtime errors in production. - Ensure migration/table helper logging is available via a module-level logger to surface migration issues. - Add unit tests to validate expiry, refresh detection, and metadata JSON handling to prevent regressions. ### Description - Imported `timedelta` from `datetime` and initialized a module-level `loguru` logger via `from loguru import logger` in `backend/models/unified_oauth_tokens.py` to support `needs_refresh` computations and logging. - Renamed the model property `metadata` to `token_metadata` while keeping the backing column `metadata_json` and implemented JSON serialization/deserialization in the new getter/setter. - Updated internal references to use `token_metadata` (including the `details` block in `to_connection_status`) and removed a duplicate local import of `logger`. - Added unit tests at `backend/tests/models/test_unified_oauth_tokens.py` validating `is_expired`, `needs_refresh`, metadata serialization round-trip, and graceful handling of invalid JSON. ### Testing - Ran the model test file with `pytest -q backend/tests/models/test_unified_oauth_tokens.py`, which completed with `6 passed` and warnings; all tests passed. - The tests exercise expiry detection, refresh-buffer logic, metadata set/get round-trip, and invalid-JSON fallback behavior and succeeded. ------ [Codex Task](https://chatgpt.com/codex/tasks/task_e_698c30730c3883289d803fecf1dc914b) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 23:35:04 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ALwrity#310
No description provided.