Skip to content

Commit 52e2ead

Browse files
authored
fix(Lifecycle): don't cache the project (#892)
1 parent 1554c9e commit 52e2ead

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

craft_application/services/lifecycle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,6 @@ class LifecycleService(base.AppService):
125125
LifecycleManager on initialisation.
126126
"""
127127

128-
_project: models.Project
129-
130128
def __init__(
131129
self,
132130
app: AppMetadata,
@@ -145,11 +143,14 @@ def __init__(
145143
@override
146144
def setup(self) -> None:
147145
"""Initialize the LifecycleManager with previously-set arguments."""
148-
self._project = self._services.get("project").get()
149146
self._lcm = self._init_lifecycle_manager()
150147
callbacks.register_post_step(self.post_prime, step_list=[Step.PRIME])
151148
callbacks.register_configure_overlay(repositories.enable_overlay_eol)
152149

150+
@property
151+
def _project(self) -> models.Project:
152+
return self._services.get("project").get()
153+
153154
def _get_build(self) -> craft_platforms.BuildInfo:
154155
"""Get the build for this run."""
155156
plan = self._services.get("build_plan").plan()

docs/reference/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
Changelog
55
*********
66

7+
5.9.1 (2025-09-04)
8+
------------------
9+
10+
Services
11+
========
12+
13+
- The Lifecycle Service no longer improperly caches the project (fixes ``adopt-info``).
14+
15+
716
5.9.0 (2025-08-29)
817
------------------
918

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: pack-bare-base
2-
version: "0.1"
32
summary: Test packing with a bare base.
43

54
base: bare
@@ -8,6 +7,12 @@ platforms:
87
amd64:
98
build-on: [amd64, arm64, ppc64el, s390x, riscv64]
109

10+
adopt-info: my-test # Check that adopt-info works.
11+
1112
parts:
1213
my-test:
1314
plugin: nil
15+
override-pull: |
16+
craftctl set version=1.2.3
17+
override-build: |
18+
craftctl get version | grep 1.2.3

tests/spread/testcraft/pack/task.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ execute: |
99
1010
restore: |
1111
cd "${PROJECT}"
12+
test -f "pack-${PROJECT}-1.2.3-amd64.testcraft"
1213
rm -f *.testcraft
1314
testcraft clean
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
summary: Check that testcraft fails with an unset adopt-info field
2+
3+
systems:
4+
- ubuntu-24.04-64
5+
6+
environment:
7+
CRAFT_BUILD_ENVIRONMENT/destructive: host
8+
CRAFT_MANAGED_MODE/managed: 1
9+
10+
execute: |
11+
testcraft pack |& MATCH "Project field 'version' was not set."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: unset-adopt-info
2+
summary: Test packing with adopt-info
3+
4+
base: ubuntu@24.04
5+
platforms:
6+
amd64:
7+
build-on: [amd64, arm64, ppc64el, s390x, riscv64]
8+
9+
adopt-info: my-test # We need a version but don't supply it because we're evil!
10+
11+
parts:
12+
my-test:
13+
plugin: nil

tests/unit/services/test_lifecycle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ class LocalProject(models.Project):
720720
cache_dir=tmp_path / "cache",
721721
platform=None,
722722
)
723-
service._project = fake_project
723+
fake_services.get("project")._project_model = fake_project
724724
service._lcm = mock.MagicMock(spec=LifecycleManager)
725725
service._lcm.project_info = mock.MagicMock(spec=ProjectInfo)
726726
service._lcm.project_info.get_project_var = lambda _: "foo"

0 commit comments

Comments
 (0)