Default `charm` or `bundle` part is not added if `parts` is defined but empty in `charmcraft.yaml`.
Metadata
Current evaluation
Fixed by merged PR canonical/charmcraft#1815 (commit 2a0eb973), correcting default charm/bundle part handling in charmcraft.yaml.
Resolution: closed resolved
Reason: Merged PR #1815 addressed empty `parts: {}` handling and restored the intended default charm/bundle parts. The change is recorded as commit 2a0eb973.
Evaluated by: mr-cal-bot
No scores available.
Issue body
### Bug Description
Currently, the default charm part is added to the charmcraft project configuration using the Pydantic model validator `charmcraft.models.project.CharmcraftProject.preprocess_parts`. However, because Pydantic validators are executed in the order they are defined, and the `parts` field is defined in the parent class `craft_application.models.project.Project` while the `type` field is defined in the child class, the validator for `parts` field will always execute before validator for `type` field.
This means the `type` attributes will never exist in the `values` parameter of `preprocess_parts` validator function. This causes the `parts` not to be added if the `parts` in the charmcraft project file are defined as `{}`. However, when the `parts` field is not defined in `charmcraft.yaml`, its value will be `None`, and the default value of `charmcraft.models.project.BasesCharm.parts` will take effect, setting the parts to `{"charm": {"plugin": "charm", "source": "."}}`.
### To Reproduce
To reproduce this issue, create a `charmcraft.yaml` with the following parts. It will not execute the `charm` part when packed:
```
parts: {}
```
### Environment
Ubuntu 22.04 LTS
### charmcraft.yaml
```shell
name: charm
type: charm
bases:
- build-on:
- name: ubuntu
channel: "22.04"
run-on:
- name: ubuntu
channel: "22.04"
summary: A test charm.
description: A test charm.
# important
parts: {}
```
### Relevant log output
```shell
n/a
```
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/charmcraft#1815 (commit 2a0eb973), correcting default charm/bundle part handling in charmcraft.yaml. | |
| stealth/space-bunny-alpha | — | closed resolved | Fixed by merged PR canonical/charmcraft#1815 (commit 2a0eb973), correcting default charm/bundle part handling in charmcraft.yaml. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without a fix. Maintainers noted the behavior was original design and deferred resolution until charm and bundle parts are refactored into extensions. The issue remains pending for future architectural changes. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without a fix. Maintainers noted the behavior was original design and requires further design work for charm and bundle extensions. The issue was deferred pending redesign, with a workaround suggested but not implemented. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without a fix. Maintainer noted the behavior was original design and proposed redesigning charms and bundles as extensions instead. The issue was superseded by planned architectural changes. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Closed without a fix. Maintainers noted the behavior was original design and deferred resolution to future work on making charm and bundle extensions. No code changes were implemented. |
Update history
No update history recorded yet.
Related work
-
Likely Fixed By:
canonical/charmcraft#1815
(confidence 99%)
PR #1815 contains the reported fix for charm/bundle parts.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #596 build: don't create implicit part if parts section specified (CRAFT-633) | charmcraft | merged | PR #596 merged (merge commit 0dacae0a, bcbdd278) by cmatsuoka: charmcraft now skips the implicit `charm`/`bundle` part when an explicit `parts:` section exists (CRAFT-633), fixing #590; tests added. | |
| #514 `charmcraft build` silently omits files called out in `charmcraft.yaml` if executed from an external directory | charmcraft | closed | Fixed by merged PR canonical/charmcraft#525 (merge commit 0d78f540), which runs the parts lifecycle from the project directory so relative globbed paths resolve during external builds. | |
| #590 Unable to build a charm using the dump plugin | charmcraft | closed | Implicit charm part was merged into user-defined 'charm' part, adding invalid charm-entrypoint/charm-requirements keys. Fixed by PR #596 (merge commit 0dacae0a, CRAFT-633) which skips the implicit part when a parts: section exists. | |
| #1622 fix: reorganise charmcraft.yaml preprocessing | charmcraft | merged | Merged in #1622 (commit 7ce4182e): extensions now run first, charms with bases get a default part, and parts must be a dictionary. | |
| #471 config: add charm part to documentation (CRAFT-356) | charmcraft | merged | Merged PR #471 via commit e0b18661, documenting the charm part in the configuration schema for CRAFT-356. | |
| #395 Update the default bundle from `charmcraft init` | charmcraft | merged | Merged PR #395 as commit 18e8e71b, improving charmcraft init metadata and moving contributor guidance from README into CONTRIBUTING.md. |