Skip to content

Migrate ScalingGroupOpts from attrs/trafaret to Pydantic BaseModel #9715

@HyeockJinKim

Description

@HyeockJinKim

Refactor ScalingGroupOpts from attrs + trafaret + JSONSerializableMixin to Pydantic BaseModel + PydanticColumn.

FairShareScalingGroupSpec in the same ScalingGroupRow already uses this pattern as reference.

Scope

  • Replace @attr.define with Pydantic BaseModel (frozen=True)
  • to_json() → model_dump(mode="json"), from_json() → model_validate()
  • Remove as_trafaret() validation — use Pydantic validators instead
  • StructuredJSONObjectColumn → PydanticColumn column type
  • Backward compatibility via Pydantic field defaults for existing JSON data
  • Update data layer ScalingGroupSchedulerOptions dataclass accordingly
  • Update GraphQL resource group mutations and legacy GQL

Key Files

  • models/scaling_group/row.py — ScalingGroupOpts class + column type
  • models/scaling_group/types.py — FairShareScalingGroupSpec reference
  • data/scaling_group/types.py — ScalingGroupSchedulerOptions
  • repositories/scaling_group/ — creators, updaters, options
  • api/gql/resource_group/ — types, resolver
  • api/gql_legacy/scaling_group.py

Success Criteria

  • ScalingGroupOpts inherits from BaseModel with frozen=True config
  • PydanticColumn used instead of StructuredJSONObjectColumn for scheduler_opts
  • Existing JSON data (without new fields) loads correctly via Pydantic defaults
  • ScalingGroup create/update via GraphQL works with new model
  • All ScalingGroupOpts fields serialized/deserialized correctly round-trip
  • pants lint/check passes for affected packages
  • pants test passes for affected packages

JIRA Issue: BA-4911

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions