Merge ~andrey-fedoseev/launchpad:snap-base-features into launchpad:master

Proposed by Andrey Fedoseev
Status: Merged
Approved by: Andrey Fedoseev
Approved revision: ccca464284b404717036632ad5e003ac6d3b50b9
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~andrey-fedoseev/launchpad:snap-base-features
Merge into: launchpad:master
Diff against target: 37 lines (+8/-1)
2 files modified
lib/lp/snappy/model/snapbase.py (+3/-1)
lib/lp/snappy/tests/test_snapbase.py (+5/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+431181@code.launchpad.net

Commit message

Fix the case when `SnapBase.feature` is `None`

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

I do not know what a SnapBase is, and the docstring for ISnapBase isn't helpful at all ("A base for snaps."), but I still wonder whether we could initialize `features` as an empty dict, so we could save us those `is None` checks.

Revision history for this message
Andrey Fedoseev (andrey-fedoseev) wrote :

None is an existing value in the database that we need to account for.

On Fri, Oct 7, 2022, 11:17 Jürgen Gmach <email address hidden>
wrote:

> I do not know what a SnapBase is, and the docstring for ISnapBase isn't
> helpful at all ("A base for snaps."), but I still wonder whether we could
> initialize `features` as an empty dict, so we could save us those `is None`
> checks.
> --
>
> https://code.launchpad.net/~andrey-fedoseev/launchpad/+git/launchpad/+merge/431181
> You are the owner of ~andrey-fedoseev/launchpad:snap-base-features.
>
>

Revision history for this message
Jürgen Gmach (jugmac00) wrote :

How did they land in the database in the first place?

Could we convert them to empty dicts?

Revision history for this message
Andrey Fedoseev (andrey-fedoseev) wrote :

This is a new nullable column that's been added recently

On Fri, Oct 7, 2022, 11:59 Jürgen Gmach <email address hidden>
wrote:

> How did they land in the database in the first place?
>
> Could we convert them to empty dicts?
> --
>
> https://code.launchpad.net/~andrey-fedoseev/launchpad/+git/launchpad/+merge/431181
> You are the owner of ~andrey-fedoseev/launchpad:snap-base-features.
>
>

Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/snappy/model/snapbase.py b/lib/lp/snappy/model/snapbase.py
2index b6e8b33..a67159b 100644
3--- a/lib/lp/snappy/model/snapbase.py
4+++ b/lib/lp/snappy/model/snapbase.py
5@@ -74,7 +74,7 @@ class SnapBase(Storm):
6
7 is_default = Bool(name="is_default", allow_none=False)
8
9- _features = PgJSON(name="features", allow_none=False)
10+ _features = PgJSON(name="features", allow_none=True)
11
12 def __init__(
13 self,
14@@ -98,6 +98,8 @@ class SnapBase(Storm):
15
16 @property
17 def features(self) -> Dict[Item, bool]:
18+ if self._features is None:
19+ return {}
20 features = {}
21 for token, is_enabled in self._features.items():
22 try:
23diff --git a/lib/lp/snappy/tests/test_snapbase.py b/lib/lp/snappy/tests/test_snapbase.py
24index 978e8b6..e7cd522 100644
25--- a/lib/lp/snappy/tests/test_snapbase.py
26+++ b/lib/lp/snappy/tests/test_snapbase.py
27@@ -93,6 +93,11 @@ class TestSnapBase(TestCaseWithFactory):
28 snap_base.features,
29 )
30
31+ def test_blank_features(self):
32+ snap_base = self.factory.makeSnapBase(name="foo")
33+ removeSecurityProxy(snap_base)._features = None
34+ self.assertEqual({}, snap_base.features)
35+
36
37 class TestSnapBaseProcessors(TestCaseWithFactory):
38

Subscribers

People subscribed via source and target branches

to status/vote changes: