posit-dev / posit-dev/images-shared

Bakery: Soften error or fall back when no version has `latest: true` during `create version`

Open
#511 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cvp:1 docker tdp:1
Dominant language
Python
Stars
2
Forks
0
Avg merge
4d 13h
Merged PRs (30d)
22

Description

Summary

When running bakery create version <image> <new-version> against an image where no existing version is marked latest: true, Bakery fails to populate the OS configuration for template rendering. This surfaces as an opaque Jinja2 'dict object' has no attribute 'OS' rendering error rather than a clear, actionable message — and there is no fallback to copy the OS configuration from an existing (non-latest) version.

Reproduction

In a repository configured with an image that has at least one prior version, but where no version sets latest: true, run:

bakery create version workbench-for-google-cloud-workstations '2026.04.0+526.pro2'

This was reproduced against posit-dev/images-specialized on branch workbench-2026.04. The relevant image block in bakery.yaml has a single existing version (2026.01.2+418.pro1) with an OS entry (Ubuntu 24.04, primary: true) but no latest: true on the version itself.

Observed behavior

Bakery emits warnings about the missing OS, then a template render error referencing an undefined OS attribute on the rendering context, followed by a traceback. The newly-created version directory is left on disk as well (the cleanup shutil.rmtree only fires when existing_version_dir was False at start, but in some cases the partial output persists).

Full output / stacktrace
[14:24:23] INFO     Loading Bakery config from                     config.py:374
                    /home/ianp/Projects/images-specialized/bakery.
                    yaml
           WARNING  No OSes defined for image version             version.py:178
                    '2026.04.0+526.pro2'. At least one OS should
                    be defined for complete tagging and labeling
                    of images.
           WARNING  No OS marked as primary for image version     version.py:241
                    '2026.04.0+526.pro2'. At least one OS should
                    be marked as primary for complete tagging and
                    labeling of images.
           ERROR    Failed to render template                     version.py:502
                    Containerfile.ubuntu2404.jinja2 for image
                    'workbench-for-google-cloud-workstations'
                    version '2026.04.0+526.pro2' variant
                    'Standard'
           ERROR    Failed to render template                     version.py:502
                    Containerfile.ubuntu2404.jinja2 for image
                    'workbench-for-google-cloud-workstations'
                    version '2026.04.0+526.pro2' variant
                    'Minimal'
           ERROR    Failed to create version files for image       config.py:555
                    'workbench-for-google-cloud-workstations'
                    version '2026.04.0+526.pro2'.
           ERROR    Error creating version                         create.py:242
                    ╭──── Traceback (most recent call last) ─────╮
                    │ posit_bakery/cli/create.py:233 in version  │
                    │   c.create_version(...)                    │
                    │ posit_bakery/config/config.py:559 in       │
                    │   create_version                           │
                    │   raise e                                  │
                    │ posit_bakery/config/config.py:553 in       │
                    │   create_version                           │
                    │   new_version.render_files(...)            │
                    ╰────────────────────────────────────────────╯

                    Error rendering template
                    workbench-for-google-cloud-workstations/template/Containerfile.ubuntu2404.jinja2:
                    'dict object' has no attribute 'OS'
                      - Image: workbench-for-google-cloud-workstations
                      - Version: 2026.04.0+526.pro2
                      - Variant: Standard
                      - Destination: workbench-for-google-cloud-workstations/2026.04.0+526.pro2/Containerfile.ubuntu2404.std

                    Error rendering template
                    workbench-for-google-cloud-workstations/template/Containerfile.ubuntu2404.jinja2:
                    'dict object' has no attribute 'OS'
                      - Image: workbench-for-google-cloud-workstations
                      - Version: 2026.04.0+526.pro2
                      - Variant: Minimal
                      - Destination: workbench-for-google-cloud-workstations/2026.04.0+526.pro2/Containerfile.ubuntu2404.min

                    2 template(s) returned errors

❌ Failed to create version 'workbench-for-google-cloud-workstations/2026.04.0+526.pro2'

Why this is friction

The user's mental model is reasonable: "I have one prior version with an OS configured — when I add a new version, copy that forward." Today Bakery only copies forward from the version explicitly marked latest: true, so a config that has never declared a latest version produces a stack trace instead of either a useful error or a working render.

Suggested directions

Either (or both) of these would close the gap:

  1. Soften the error. When OS resolution fails for a new version, surface a clear, actionable message at the CLI layer — e.g. "no version of <image> is marked latest: true; cannot infer OS configuration. Either mark a prior version as latest or specify OSes on the new version" — instead of letting a Jinja AttributeError escape.
  2. Fallback sequence. When no version has latest: true, fall back to copying the OS configuration from another existing version (e.g. the most recent by version order, or the only one if there is exactly one). This matches the implicit "most recent is latest" assumption users tend to bring.

Direction (2) is the more user-friendly fix; (1) is the minimum bar regardless of whether (2) lands.

Environment

  • Bakery checkout: ~/Projects/images-shared-ordered-push/posit-bakery (per the traceback paths)
  • Repo under test: posit-dev/images-specialized, branch workbench-2026.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with posit_bakery/cli/create.py and posit_bakery/config/config.py around create_version, then trace OS resolution and template rendering in version.py. Reproduce with the documented bakery create version command and inspect the existing-version cleanup path. Done means the no-latest case either falls back to a documented existing version or reports a clear actionable CLI error without exposing the Jinja traceback or leaving partial output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.