Skip to content

Conversation

nmveeresh
Copy link
Collaborator

@nmveeresh nmveeresh commented Aug 11, 2025

Fixes issue #661.

The verify_credentials.py file was using datetime.utcnow(), which caused doctest failures due to it returning a naive datetime object.

This has been replaced with timezone-aware code using datetime.now(timezone.utc) and timedelta to ensure correct datetime handling.

Key changes:

Deprecated:

import datetime
expired_payload = {'sub': 'bob', 'exp': datetime.utcnow() - datetime.timedelta(hours=1)}

Fix:

from datetime import datetime, timezone, timedelta
expired_payload = {'sub': 'bob', 'exp': datetime.now(timezone.utc) - timedelta(hours=1)}

Test Results:

SKIPPED [8] ../../.venv/mcpgateway/lib/python3.12/site-packages/_pytest/doctest.py:458: all tests skipped by +SKIP option
394 passed, 8 skipped in 11.65s

Closes #661

@nmveeresh nmveeresh self-assigned this Aug 11, 2025
@nmveeresh nmveeresh changed the title replaced deprecated code Issue - 661 (Database migration runs during doctest execution) : replaced deprecated code Aug 11, 2025
nmveeresh and others added 3 commits August 11, 2025 11:51
Signed-off-by: Veeresh K <[email protected]>
This HTML file was accidentally committed. MkDocs automatically generates HTML from the index.md file during the build process. Committed HTML files are not needed and can cause conflicts with the documentation build system.
@crivetimihai crivetimihai force-pushed the issue_661/db-migr-doctest branch from d8a14e1 to ecb82e5 Compare August 11, 2025 11:06
Copy link
Member

@crivetimihai crivetimihai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: Issue #661 - Database Migration Runs During Doctest Execution

Issue Summary

Issue #661: Database migration was being triggered during doctest execution, causing test failures due to deprecated datetime.utcnow() usage.

PR #713 Analysis

Original Changes by nmveeresh

The PR addressed the core issue by replacing deprecated datetime code:

Before (Deprecated):

import datetime 
expired_payload = {'sub': 'bob', 'exp': datetime.utcnow() - datetime.timedelta(hours=1)}

After (Fixed):

from datetime import datetime, timezone, timedelta
expired_payload = {'sub': 'bob', 'exp': datetime.now(timezone.utc) - timedelta(hours=1)}

Files Modified

  1. mcpgateway/utils/verify_credentials.py - Fixed deprecated datetime usage
  2. mcpgateway/main.py - Related updates for datetime handling
  3. docs/docs/using/plugins/index.html - Accidentally added file (now removed)

Additional Cleanup Performed

Removed Unnecessary File

  • File: docs/docs/using/plugins/index.html
  • Reason: Auto-generated HTML file that shouldn't be committed
  • Details:
    • MkDocs automatically generates HTML from markdown files during build
    • This was likely generated by VSCode's markdown preview
    • Including it would conflict with MkDocs build system
    • Removed in commit: ecb82e5

Current Branch Status

  • Branch: issue_661/db-migr-doctest
  • Rebased onto latest main (includes recent PRs #710, #711, #712)
  • Ready for final review and merge

Test Results

As reported in original PR:

  • 394 tests passed
  • 8 skipped (by +SKIP option)

Recommendation

The PR correctly fixes the datetime deprecation issue that was causing doctest failures. With the removal of the accidentally committed HTML file and successful rebase to latest main, this PR is ready to merge.

Commits in Branch

  1. 4a6ccbe - replaced deprecated code (original fix)
  2. 3f449df - removed whitespaces (cleanup)
  3. ecb82e5 - Remove auto-generated index.html file (additional cleanup)

@crivetimihai crivetimihai merged commit 5385eb1 into main Aug 11, 2025
37 checks passed
@crivetimihai crivetimihai deleted the issue_661/db-migr-doctest branch August 11, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Database migration runs during doctest execution
2 participants