Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Conversation

@whitdog47
Copy link
Contributor

This PR refactors the Link model to address issues related to JSON serialization. The primary changes involve replacing the AnyHttpUrl type with str in the SQLAlchemy model and implementing a robust validation mechanism at the API layer to ensure URLs are valid before being persisted to the database.

Key Changes

  1. Model Update:

    • Changed the href field type from AnyHttpUrl to str in the Link SQLAlchemy model.
    • This change was necessary because AnyHttpUrl cannot be directly serialized to JSON, and the list of Link objects are stored as JSON in the source table.
  2. Validation Mechanism:

    • We introduced a validation function using Pydantic's AnyHttpUrl to validate URLs before they are stored in the database.
    • This ensures that only valid URLs are persisted, while maintaining the flexibility to store them as strings.

@whitdog47 whitdog47 requested review from Copilot and kevgliss May 22, 2025 23:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors URL handling for the Link model by switching the href type from AnyHttpUrl to str and adding an API layer validation mechanism using Pydantic.

  • Update of the Link model in models.py to use str for href with a comment noting the change for JSON serialization.
  • Introduction of a LinkValidator and an all_links_are_valid function in service.py for URL validation before database persistence.
  • Minor adjustments in error handling in get_by_name_or_raise for missing sources.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/dispatch/data/source/service.py Added URL validation logic, logging for invalid URLs, and updated error handling in source retrieval.
src/dispatch/data/source/models.py Changed the Link.href type from AnyHttpUrl to str and updated inline documentation about URL validation.

@whitdog47 whitdog47 closed this May 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants