Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charmcraft/application/commands/lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _validate_bases_indices(self, bases_indices):
if bases_indices is None:
return

project = cast(models.Charm, self._services.project)
project = cast(models.Charm, self._services.project.get())

msg = "Bases index '{}' is invalid (must be >= 0 and fit in configured bases)."
len_configured_bases = len(project.bases)
Expand Down
2 changes: 1 addition & 1 deletion charmcraft/application/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _run(self, parsed_args: argparse.Namespace, **kwargs: Any) -> int | None:
return 77 # permission denied from sysexits.h

builder = self._services.remote_build
project = cast(models.Charm, self._services.project)
project = cast(models.Charm, self._services.project.get())
config = cast(dict[str, Any], self.config)
project_dir = (
pathlib.Path(config.get("global_args", {}).get("project_dir") or ".")
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies = [
"distro>=1.7.0",
"docker>=7.0.0",
"humanize>=2.6.0",
"jsonschema~=4.0",
"jinja2",
"pydantic~=2.0",
"python-dateutil",
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/commands/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from charmcraft import application, models, services, utils
from charmcraft.application.commands import lifecycle
from charmcraft.application.commands.remote import RemoteBuild
from charmcraft.store.models import Library

if TYPE_CHECKING:
Expand Down Expand Up @@ -272,3 +273,31 @@ def test_move_artifacts_creates_output_dir(
pack._run(parsed_args)

assert (output_dir / artifact_name).read_text() == "charm content"


# Reproducer for https://github.com/canonical/charmcraft/issues/2598
def test_remote_build_project_name_attribute_error(
service_factory: services.ServiceFactory,
):
"""RemoteBuild._run should complete without AttributeError.

This test reproduces the bug where self._services.project returns a
ProjectService object instead of the actual project model, causing
`project.name` to raise AttributeError at the get_build_id() call.
"""
cmd = RemoteBuild({"app": application.APP_METADATA, "services": service_factory})
parsed_args = argparse.Namespace(
launchpad_accept_public_upload=True,
recover=False,
launchpad_timeout=0,
)

# Prevent an actual Launchpad connection while still reaching the buggy line.
mock_builder = mock.MagicMock()
mock_builder.start_builds.return_value = []
service_factory.remote_build = mock_builder

# Bug: self._services.project is a ProjectService (no .name attribute).
# This call should succeed but currently raises:
# AttributeError: 'ProjectService' object has no attribute 'name'
cmd._run(parsed_args)
Loading