← Back to issue list

Craft-parts cannot parse advanced grammar in `stage` and `prime` fields

View original Github issue

Metadata

Project
craft-parts
Number
#874
Type
issue
State
open
Author
mr-cal
Labels
Created
Updated
Closed

Current evaluation

craft-parts crashes with AttributeError when stage/prime entries use advanced grammar. Maintainer triaged: root cause is snapcraft's expand-extensions not processing grammar for prime (snapcraft#5583, open). No activity for ~18 months.

Suggested action: keep open

Reason: Maintainer lengau triaged this on 2024-10-09, stating 'craft-parts doesn't need to handle grammar' and 'We should probably keep this bug around though', pointing at snapcraft's expand-extensions as the real fix location. The related issue canonical/snapcraft#5583 is still open and triaged (SNAPCRAFT-1184), and the crashing RelativePathStr validator still exists in constraints.py/parts.py, so the issue remains valid despite ~18 months of inactivity.

Impact: 45 Quick Win: 29.25 Staleness: 70 Complexity: 35 Confidence: 80 Support Request: 5

Issue body

### Bug Description Craft-parts assumes `prime` and `stage` entries are strings. This is not true if advanced grammar is used. Craft-parts needs to be able to unmarshal parts with advanced grammar. The problematic code is [here](https://github.com/canonical/craft-parts/blob/836a4fb7fbba405fc06e4da4d51117cdb99982b9/craft_parts/constraints.py#L35)). ### To Reproduce See a snapcraft reproducer in https://bugs.launchpad.net/snapcraft/+bug/2083964 ### part yaml ```shell parts: my-part: plugin: nil prime: - on amd64: - usr/lib/*/libvpl.so.* ``` ### Relevant log output ```shell 2024-10-09 09:12:00.397 Starting snapcraft, version 8.4.2 2024-10-09 09:12:00.397 Log verbosity level set to BRIEF 2024-10-09 09:12:00.397 Preparing application... 2024-10-09 09:12:00.397 Configuring application... 2024-10-09 09:12:00.398 Setting up ConfigService 2024-10-09 09:12:00.507 Build plan: platform=None, build_for=None 2024-10-09 09:12:00.507 Running snapcraft expand-extensions on host 2024-10-09 09:12:00.521 snapcraft internal error: AttributeError("'dict' object has no attribute 'startswith'") 2024-10-09 09:12:00.522 Traceback (most recent call last): 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/application.py", line 568, in run 2024-10-09 09:12:00.522 return_code = self._run_inner() 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/snapcraft/application.py", line 215, in _run_inner 2024-10-09 09:12:00.522 return_code = super()._run_inner() 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/application.py", line 549, in _run_inner 2024-10-09 09:12:00.522 return_code = dispatcher.run() or os.EX_OK 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_cli/dispatcher.py", line 487, in run 2024-10-09 09:12:00.522 return self._loaded_command.run(self._parsed_command_args) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/snapcraft/commands/extensions.py", line 137, in run 2024-10-09 09:12:00.522 project_data = models.Project.unmarshal(yaml_data_for_arch) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/models/base.py", line 61, in unmarshal 2024-10-09 09:12:00.522 return cls.model_validate(data) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/pydantic/main.py", line 568, in model_validate 2024-10-09 09:12:00.522 return cls.__pydantic_validator__.validate_python( 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_application/models/project.py", line 250, in _validate_part 2024-10-09 09:12:00.522 craft_parts.validate_part(part) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/parts.py", line 648, in validate_part 2024-10-09 09:12:00.522 _get_part_spec(data) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/parts.py", line 679, in _get_part_spec 2024-10-09 09:12:00.522 return PartSpec(**part_spec) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/pydantic/main.py", line 193, in __init__ 2024-10-09 09:12:00.522 self.__pydantic_validator__.validate_python(data, self_instance=self) 2024-10-09 09:12:00.522 File "/snap/snapcraft/12783/lib/python3.10/site-packages/craft_parts/constraints.py", line 44, in _validate_relative_path_str 2024-10-09 09:12:00.522 if path.startswith("/"): 2024-10-09 09:12:00.522 AttributeError: 'dict' object has no attribute 'startswith' 2024-10-09 09:12:00.522 Full execution log: '/home/developer/.local/state/snapcraft/log/snapcraft-20241009-091200.396666.log' ```

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.8-27b
Impact: 45
Quick Win: 29.25
Staleness: 70
Complexity: 35
Confidence: 80
Support Request: 5
keep open craft-parts crashes with AttributeError when stage/prime entries use advanced grammar. Maintainer triaged: root cause is snapcraft's expand-extensions not processing grammar for prime (snapcraft#5583, open). No activity for ~18 months.
qwen/qwen3.6-35b-a3b
Staleness: 90
Complexity: 30
Confidence: 85
Support Request: 10
close stale Craft-parts fails to parse advanced grammar in stage/prime fields, causing an AttributeError during YAML unmarshalling. A maintainer clarified that grammar processing belongs upstream, leaving the issue inactive and irrelevant to this repository.
qwen3.6-35b-a3b-mtp-q6
Staleness: 85
Complexity: 30
Confidence: 90
Support Request: 0
needs triage craft-parts fails to parse advanced grammar in stage and prime fields, raising an AttributeError during unmarshalling. Open, unlabelled, awaiting maintainer assessment.
qwen3.6-35b-a3b-mtp-q6
Staleness: 80
Complexity: 45
Confidence: 75
Support Request: 10
keep open craft-parts fails to unmarshal stage and prime fields containing advanced grammar. Open and under discussion on whether craft-parts should parse grammar or snapcraft is misprocessing it. Currently inactive.

Update history

No update history recorded yet.

Related work

  • Related To: canonical/snapcraft#5583 (confidence 85%)

    Same crash tracked in snapcraft: expand-extensions only processes grammar for a fixed key list that excludes prime; open and triaged with internal ticket SNAPCRAFT-1184. The maintainer here identified this as the actual fix location.

Related issues

Issue Project State Summary Similarity
#5583 expand-extensions fails to process advanced grammar in parts/part/prime snapcraft open expand-extensions crashes with AttributeError when a part's prime keyword uses advanced grammar (on amd64). Grammar is only processed for a fixed key list, not prime. Triaged, minimal reproducer provided, internal ticket SNAPCRAFT-1184 opened.
81%