Skip to content

scaffold_from_template flattens the template tycoon.yml when stamping schema_version #185

Description

@db-tycoon-stephen

Found during review of #178 (T2-4).

scaffold_from_template copies the template tycoon.yml with shutil.copy2, which preserves the file verbatim — then immediately undoes that with a yaml.safe_load / yaml.dump round-trip to stamp schema_version:

shutil.copy2(src_yml, dst_yml)
_raw = yaml.safe_load(dst_yml.read_text()) or {}
_raw["schema_version"] = SCHEMA_VERSION
dst_yml.write_text(yaml.dump(_raw, default_flow_style=False, sort_keys=False))

Effect

Verified against src/tycoon/templates/nyc-transit/tycoon.yml:

  • 41 lines → 37
  • all 5 blank-line section separators stripped, so the file arrives as one dense block
  • schema_version appended at line 36, at the bottom, rather than next to version: at the top

This is the first file a new user opens after tycoon init --template.

Why it's inconsistent

migrate_project deliberately uses ruamel.yaml precisely to preserve comments and blank lines. This path throws that away for the same stamping job.

Suggested fix

Drop the manual round-trip and call migrate_project(dst_yml.parent) after the copy. It's ruamel-based, already tested, idempotent, and stamps schema_version plus metadata: defaults in one shot.

scaffold_blank_project is unaffected — it builds the dict itself, so there's no formatting to preserve.


Mirrored in Jira: PTC-110 (Subtask of PTC-84, [Rewrite M2]). Dev work continues here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: configtycoon.yml schema + config singletonarea: scaffolddbt, Rill, project scaffoldingbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions