Skip to content

Beamline ServiceAccounts Validation Errors Due to Missing Keys #210

@anubhutisinha04

Description

@anubhutisinha04

Summary

Few Beamline documents trigger Pydantic validation errors when loaded:

service_accounts.operator - Field required
endstations.0.service_accounts.<fields> - Field required

This blocks workflows (e.g. detector onboarding, data security sync) for affected beamlines.

Root Cause

In ServiceAccounts the fields are declared as:

ioc: Optional[str]
workflow: Optional[str]
bluesky: Optional[str]
epics_services: Optional[str]
operator: Optional[str]

In Pydantic v2, Optional[T] without a default still makes the field required: the key must be present, though its value may be None. Documents edited directly in MongoDB have:

  • Missing keys (e.g. operator absent entirely)
  • Empty {} for an endstation’s service_accounts
    This produces “Field required” errors (missing keys), not “None disallowed.”

Current State

  • Currently updating values directly in MongoDB (dev and prod) (no API support yet).
  • Potential absence of Validation rules in MongoDB (need to verify)

Short-Term Fix

  1. To update the fields in both DEV and PROD – need access to ssh into hosts: mongo1 (MongoDB), api-dev1 (dev API), api4 (prod API), mongodev.

Recommended Model Change

  • Add a PATCH endpoint which is admin locked to be able to make changes and enforce that all required service_accounts fields are present (reject partial or empty dicts).
  • Add a MongoDB validation rule so new entries always have the required fields and stay consistent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions