Merge ~cjwatson/launchpad:scan-generic-detect-float-version into launchpad:master

Proposed by Colin Watson
Status: Needs review
Proposed branch: ~cjwatson/launchpad:scan-generic-detect-float-version
Merge into: launchpad:master
Diff against target: 67 lines (+45/-0)
2 files modified
lib/lp/soyuz/model/archivejob.py (+8/-0)
lib/lp/soyuz/tests/test_archivejob.py (+37/-0)
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+430891@code.launchpad.net

Commit message

Explicitly check type of report's version property

Description of the change

This is an easy mistake to make in YAML, so check for it explicitly to avoid a confusing OOPS later on.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :

Unmerged commits

5e7bb42... by Colin Watson

Explicitly check type of report's version property

This is an easy mistake to make in YAML, so check for it explicitly to
avoid a confusing OOPS later on.

Succeeded
[SUCCEEDED] docs:0 (build)
[SUCCEEDED] lint:0 (build)
[SUCCEEDED] mypy:0 (build)
13 of 3 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/soyuz/model/archivejob.py b/lib/lp/soyuz/model/archivejob.py
2index f73cec1..0d9bf2c 100644
3--- a/lib/lp/soyuz/model/archivejob.py
4+++ b/lib/lp/soyuz/model/archivejob.py
5@@ -623,6 +623,14 @@ class CIBuildUploadJob(ArchiveJobDerived):
6 or "version" not in properties
7 ):
8 return {}
9+ if not isinstance(properties["version"], str):
10+ logger.warning(
11+ "Failed to scan generic artifacts: expected version to be a "
12+ "string, got %r (%s)",
13+ properties["version"],
14+ type(properties["version"]).__name__,
15+ )
16+ return {}
17
18 all_metadata = {}
19 for path in paths:
20diff --git a/lib/lp/soyuz/tests/test_archivejob.py b/lib/lp/soyuz/tests/test_archivejob.py
21index 623c7cb..40c3341 100644
22--- a/lib/lp/soyuz/tests/test_archivejob.py
23+++ b/lib/lp/soyuz/tests/test_archivejob.py
24@@ -651,6 +651,43 @@ class TestCIBuildUploadJob(TestCaseWithFactory):
25 ),
26 )
27
28+ def test__scanFiles_generic_bad_version(self):
29+ # An easy mistake to make in YAML is to declare the version as a
30+ # float rather than a string. The scan job explicitly checks for
31+ # this.
32+ logger = self.useFixture(FakeLogger())
33+ archive = self.factory.makeArchive()
34+ distroseries = self.factory.makeDistroSeries(
35+ distribution=archive.distribution
36+ )
37+ build = self.makeCIBuild(archive.distribution)
38+ report = self.factory.makeRevisionStatusReport(
39+ title="build-source", ci_build=build
40+ )
41+ report.update(
42+ properties={
43+ "name": "foo",
44+ "version": 1.0,
45+ "source": True,
46+ }
47+ )
48+ job = CIBuildUploadJob.create(
49+ build,
50+ build.git_repository.owner,
51+ archive,
52+ distroseries,
53+ PackagePublishingPocket.RELEASE,
54+ target_channel="edge",
55+ )
56+ tmpdir = Path(self.useFixture(TempDir()).path)
57+ (tmpdir / "foo-1.0").write_bytes(b"source artifact")
58+ self.assertEqual({}, job._scanFiles(report, tmpdir))
59+ expected_logs = [
60+ "Failed to scan generic artifacts: expected version to be a "
61+ "string, got 1.0 (float)",
62+ ]
63+ self.assertEqual(expected_logs, logger.output.splitlines())
64+
65 def test_run_indep(self):
66 archive = self.factory.makeArchive(
67 repository_format=ArchiveRepositoryFormat.PYTHON

Subscribers

People subscribed via source and target branches

to status/vote changes: