Skip to content

Auto-populate dynamic service-info timestamps#56

Open
AaryanCode69 wants to merge 1 commit intoelixir-cloud-aai:devfrom
AaryanCode69:fix/30-auto-populate-service-info-timestamps
Open

Auto-populate dynamic service-info timestamps#56
AaryanCode69 wants to merge 1 commit intoelixir-cloud-aai:devfrom
AaryanCode69:fix/30-auto-populate-service-info-timestamps

Conversation

@AaryanCode69
Copy link
Copy Markdown

@AaryanCode69 AaryanCode69 commented Mar 23, 2026

Description

This change removes the hardcoded createdAt and updatedAt values from the default service-info configuration and makes them optional in the custom config model. The registry now auto-populates those timestamps when seeding service-info from configuration, while still preserving explicitly provided values if they exist.

This keeps the startup-generated service-info metadata current without requiring manual timestamp updates in config.yaml.

Dependencies required for this change: none.

Fixes #30

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not reduced the existing code coverage
  • I have added docstrings following the Python style guidelines of this project to all new modules, classes, methods and functions are documented with docstrings following; I have updated any previously existing docstrings, if applicable
  • I have updated any sections of the app's documentation that are affected by the proposed changes, if applicable

Summary by Sourcery

Auto-manage service-info timestamps from configuration while keeping existing values when explicitly provided.

Bug Fixes:

  • Ensure service-info records are updated only when configuration changes, ignoring dynamically managed timestamp differences.

Enhancements:

  • Make service-info createdAt and updatedAt fields optional in the custom configuration model and exclude null values when seeding from config.
  • Introduce automatic population and comparison helpers for createdAt and updatedAt fields based on current time and existing database values.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 23, 2026

Reviewer's Guide

Makes service-info timestamps optional in config and auto-populates them at startup while ignoring dynamic timestamp differences when deciding whether to reuse existing service-info.

Sequence diagram for auto-populating service-info timestamps from config

sequenceDiagram
    participant AppStartup
    participant RegisterServiceInfo
    participant DB as ServiceInfoCollection

    AppStartup->>RegisterServiceInfo: set_service_info_from_config()
    RegisterServiceInfo->>DB: get_service_info()
    alt service-info exists
        DB-->>RegisterServiceInfo: db_info
    else service-info not found
        DB-->>RegisterServiceInfo: NotFound exception
        RegisterServiceInfo->>RegisterServiceInfo: db_info = {}
    end

    RegisterServiceInfo->>RegisterServiceInfo: service_info = _get_service_info_from_config(db_info or None)
    RegisterServiceInfo->>RegisterServiceInfo: ignored_fields = _dynamic_timestamp_fields()
    RegisterServiceInfo->>RegisterServiceInfo: db_core = _without_fields(db_info, ignored_fields)
    RegisterServiceInfo->>RegisterServiceInfo: service_core = _without_fields(service_info, ignored_fields)

    alt db_core == service_core and _has_fields(db_info, ignored_fields)
        RegisterServiceInfo-->>AppStartup: log Using available service info
    else
        RegisterServiceInfo->>DB: _upsert_service_info(service_info)
        DB-->>RegisterServiceInfo: upsert ok
        RegisterServiceInfo-->>AppStartup: log Service info registered
    end
Loading

Class diagram for updated service-info config and controller

classDiagram
    class RegisterServiceInfo {
        - registry_conf
        - foca_conf
        - host_name
        - external_port
        - api_path
        - conf_info
        - collection
        + __init__() void
        + set_service_info_from_config() void
        + set_service_info_from_app_context(headers Dict) None
        - _get_service_info_from_config(db_info Dict) Dict
        - _current_timestamp() str
        - _dynamic_timestamp_fields() FrozenSet~str~
        - _has_fields(data Dict, fields FrozenSet~str~) bool
        - _without_fields(data Dict, fields FrozenSet~str~) Dict
        - _upsert_service_info(data Dict) None
        - get_service_info() Dict
        - _get_headers() Dict
    }

    class ServiceInfoConfig {
        + id str
        + name str
        + type str
        + description str
        + organization OrganizationConfig
        + contactUrl str
        + documentationUrl str
        + createdAt Optional~str~
        + updatedAt Optional~str~
        + environment str
        + version str
    }

    class OrganizationConfig {
        + name str
        + url str
    }

    class TIMESTAMP_FIELDS {
        + createdAt
        + updatedAt
    }

    RegisterServiceInfo --> ServiceInfoConfig : uses
    ServiceInfoConfig --> OrganizationConfig : has
    RegisterServiceInfo --> TIMESTAMP_FIELDS : reads
Loading

Flow diagram for deciding whether to reuse or update service-info

flowchart TD
    A[Start: set_service_info_from_config] --> B[Fetch existing db_info]
    B --> C{db_info found?}
    C -- No --> D[Set db_info to empty dict]
    C -- Yes --> E[Use returned db_info]
    D --> F[Build service_info from config and timestamps]
    E --> F
    F --> G[Determine ignored_fields using _dynamic_timestamp_fields]
    G --> H[Compute db_core = db_info without ignored_fields]
    H --> I[Compute service_core = service_info without ignored_fields]
    I --> J{db_core equals service_core
and db_info has all ignored_fields?}
    J -- Yes --> K[Log Using available service info]
    K --> L[End]
    J -- No --> M[Upsert service_info into database]
    M --> N[Log Service info registered]
    N --> L[End]
Loading

File-Level Changes

Change Details Files
Auto-populate createdAt/updatedAt when seeding service-info from config and avoid unnecessary updates when only timestamps differ.
  • Store service_info config dict without None values to better reflect optional fields.
  • On set_service_info_from_config, build the service-info document via a helper that fills in createdAt/updatedAt if missing, reusing existing DB createdAt when available and always setting updatedAt to the current time if not provided.
  • Compare existing DB service-info with the would-be new document while ignoring dynamically managed timestamp fields, and skip updates if only those fields differ and the DB already has them.
cloud_registry/ga4gh/registry/service_info.py
Make service-info timestamps optional in the custom configuration model and stop hardcoding them in the default config.
  • Change ServiceInfoConfig model so createdAt and updatedAt are optional string fields defaulting to None.
  • Remove createdAt and updatedAt entries from the default service-info section in config.yaml so they can be auto-populated at runtime.
cloud_registry/service_models/custom_config.py
cloud_registry/config.yaml

Assessment against linked issues

Issue Objective Addressed Explanation
#30 Make createdAt and updatedAt configuration variables non-hardcoded/optional rather than required fixed values in configuration.
#30 Implement automatic population and update of createdAt and updatedAt timestamps when registering/seeding service-info from configuration, while preserving explicitly provided values if present.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The logic in set_service_info_from_config for comparing db_info and service_info while special-casing timestamp fields is fairly dense; consider extracting the comparison into a named helper with a short docstring to make the intent and conditions easier to follow.
  • In _has_fields, you’re checking field presence via truthiness (data.get(field)), which will treat empty strings or other falsy-but-present values as missing; if that’s not intentional, consider using field in data instead.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The logic in `set_service_info_from_config` for comparing `db_info` and `service_info` while special-casing timestamp fields is fairly dense; consider extracting the comparison into a named helper with a short docstring to make the intent and conditions easier to follow.
- In `_has_fields`, you’re checking field presence via truthiness (`data.get(field)`), which will treat empty strings or other falsy-but-present values as missing; if that’s not intentional, consider using `field in data` instead.

## Individual Comments

### Comment 1
<location path="cloud_registry/service_models/custom_config.py" line_range="194-197" />
<code_context>
     organization: OrganizationConfig
     contactUrl: str
     documentationUrl: str
-    createdAt: str
-    updatedAt: str
+    createdAt: Optional[str] = None
+    updatedAt: Optional[str] = None
     environment: str
     version: str
</code_context>
<issue_to_address>
**question (bug_risk):** Making createdAt/updatedAt optional may allow silently missing timestamps if validation elsewhere doesn’t enforce them.

This change makes the model dependent on `RegisterServiceInfo` (or similar logic) to always set these fields. If any code path constructs and persists `ServiceInfoConfig` directly (e.g., other services, utilities, or migrations), it could save documents without timestamps. Please verify that all persistence paths either run through the auto-timestamp logic or explicitly set these values.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines -194 to 197
createdAt: str
updatedAt: str
createdAt: Optional[str] = None
updatedAt: Optional[str] = None
environment: str
version: str
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

question (bug_risk): Making createdAt/updatedAt optional may allow silently missing timestamps if validation elsewhere doesn’t enforce them.

This change makes the model dependent on RegisterServiceInfo (or similar logic) to always set these fields. If any code path constructs and persists ServiceInfoConfig directly (e.g., other services, utilities, or migrations), it could save documents without timestamps. Please verify that all persistence paths either run through the auto-timestamp logic or explicitly set these values.

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.

Add support for auto-population of dynamic config variables

1 participant