← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:stormify-sourcepackagename into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:stormify-sourcepackagename into launchpad:master.

Commit message:
Convert SourcePackageName to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/450323

`SourcePackageName.potemplates` and `SourcePackageName.packagings` were unused, so I removed them.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-sourcepackagename into launchpad:master.
diff --git a/lib/lp/archiveuploader/tests/test_uploadprocessor.py b/lib/lp/archiveuploader/tests/test_uploadprocessor.py
index de16e04..7670f7c 100644
--- a/lib/lp/archiveuploader/tests/test_uploadprocessor.py
+++ b/lib/lp/archiveuploader/tests/test_uploadprocessor.py
@@ -1096,7 +1096,11 @@ class TestUploadProcessor(StatsMixin, TestUploadProcessorBase):
         self._checkPartnerUploadEmailSuccess()
 
         # Find the sourcepackagerelease and check its component.
-        foocomm_name = SourcePackageName.selectOneBy(name="foocomm")
+        foocomm_name = (
+            IStore(SourcePackageName)
+            .find(SourcePackageName, name="foocomm")
+            .one()
+        )
         foocomm_spr = (
             IStore(SourcePackageRelease)
             .find(SourcePackageRelease, sourcepackagename=foocomm_name)
diff --git a/lib/lp/registry/doc/distribution.rst b/lib/lp/registry/doc/distribution.rst
index e618751..0ff2739 100644
--- a/lib/lp/registry/doc/distribution.rst
+++ b/lib/lp/registry/doc/distribution.rst
@@ -77,11 +77,16 @@ have a SourcePackageName object for it.
     >>> from lp.registry.interfaces.distributionsourcepackage import (
     ...     IDistributionSourcePackage,
     ... )
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.interfaces.distributionsourcepackagerelease import (
     ...     IDistributionSourcePackageRelease,
     ... )
 
-    >>> evo = SourcePackageName.byName("evolution")
+    >>> evo = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="evolution")
+    ...     .one()
+    ... )
     >>> evo_ubuntu = ubuntu.getSourcePackage(evo)
     >>> print(evo_ubuntu.name)
     evolution
@@ -89,7 +94,6 @@ have a SourcePackageName object for it.
     >>> IDistributionSourcePackage.providedBy(evo_ubuntu)
     True
 
-    >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
     >>> sourcepackagerelease = (
     ...     IStore(SourcePackageRelease)
diff --git a/lib/lp/registry/doc/sourcepackage.rst b/lib/lp/registry/doc/sourcepackage.rst
index 462d93f..96e34c0 100644
--- a/lib/lp/registry/doc/sourcepackage.rst
+++ b/lib/lp/registry/doc/sourcepackage.rst
@@ -275,8 +275,16 @@ packaging process. Here we test the code that links all of those.
 First, let's get some useful objects from the db.
 
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
-    >>> firefox = SourcePackageName.byName("mozilla-firefox")
-    >>> pmount = SourcePackageName.byName("pmount")
+    >>> firefox = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="mozilla-firefox")
+    ...     .one()
+    ... )
+    >>> pmount = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="pmount")
+    ...     .one()
+    ... )
 
     >>> from lp.registry.model.distroseries import DistroSeries
     >>> warty = DistroSeries.get(1)
diff --git a/lib/lp/registry/model/distribution.py b/lib/lp/registry/model/distribution.py
index 81040cb..429a1e9 100644
--- a/lib/lp/registry/model/distribution.py
+++ b/lib/lp/registry/model/distribution.py
@@ -155,12 +155,7 @@ from lp.services.database.decoratedresultset import DecoratedResultSet
 from lp.services.database.enumcol import DBEnum
 from lp.services.database.interfaces import IStore
 from lp.services.database.sqlbase import SQLBase, sqlvalues
-from lp.services.database.sqlobject import (
-    BoolCol,
-    ForeignKey,
-    SQLObjectNotFound,
-    StringCol,
-)
+from lp.services.database.sqlobject import BoolCol, ForeignKey, StringCol
 from lp.services.database.stormexpr import (
     ArrayAgg,
     ArrayIntersects,
@@ -1358,9 +1353,12 @@ class Distribution(
         if ISourcePackageName.providedBy(name):
             sourcepackagename = name
         else:
-            try:
-                sourcepackagename = SourcePackageName.byName(name)
-            except SQLObjectNotFound:
+            sourcepackagename = (
+                IStore(SourcePackageName)
+                .find(SourcePackageName, name=name)
+                .one()
+            )
+            if sourcepackagename is None:
                 return None
         return DistributionSourcePackage(self, sourcepackagename)
 
@@ -1748,7 +1746,11 @@ class Distribution(
                 "published in it" % (self.displayname, pkgname)
             )
 
-        sourcepackagename = SourcePackageName.selectOneBy(name=pkgname)
+        sourcepackagename = (
+            IStore(SourcePackageName)
+            .find(SourcePackageName, name=pkgname)
+            .one()
+        )
         if sourcepackagename:
             # Note that in the source package case, we don't restrict
             # the search to the distribution release, making a best
diff --git a/lib/lp/registry/model/distroseries.py b/lib/lp/registry/model/distroseries.py
index db6564b..1fb6308 100644
--- a/lib/lp/registry/model/distroseries.py
+++ b/lib/lp/registry/model/distroseries.py
@@ -73,7 +73,6 @@ from lp.services.database.sqlobject import (
     BoolCol,
     ForeignKey,
     IntCol,
-    SQLObjectNotFound,
     StringCol,
 )
 from lp.services.database.stormexpr import WithMaterialized, fti_search
@@ -1042,9 +1041,12 @@ class DistroSeries(
     def getSourcePackage(self, name):
         """See `IDistroSeries`."""
         if not ISourcePackageName.providedBy(name):
-            try:
-                name = SourcePackageName.byName(name)
-            except SQLObjectNotFound:
+            name = (
+                IStore(SourcePackageName)
+                .find(SourcePackageName, name=name)
+                .one()
+            )
+            if name is None:
                 return None
         return getUtility(ISourcePackageFactory).new(
             sourcepackagename=name, distroseries=self
diff --git a/lib/lp/registry/model/sourcepackage.py b/lib/lp/registry/model/sourcepackage.py
index 329e692..c15b371 100644
--- a/lib/lp/registry/model/sourcepackage.py
+++ b/lib/lp/registry/model/sourcepackage.py
@@ -666,7 +666,7 @@ class SourcePackage(
         SourcePackagePublishingHistory.archive = BinaryPackageBuild.archive
         """
             % sqlvalues(
-                self.sourcepackagename,
+                self.sourcepackagename.id,
                 self.distroseries,
                 list(self.distribution.all_distro_archive_ids),
             )
diff --git a/lib/lp/registry/model/sourcepackagename.py b/lib/lp/registry/model/sourcepackagename.py
index 37974b0..e51985d 100644
--- a/lib/lp/registry/model/sourcepackagename.py
+++ b/lib/lp/registry/model/sourcepackagename.py
@@ -7,7 +7,7 @@ __all__ = [
     "getSourcePackageDescriptions",
 ]
 
-import six
+from storm.properties import Int, Unicode
 from zope.interface import implementer
 
 from lp.app.errors import NotFoundError
@@ -17,26 +17,21 @@ from lp.registry.interfaces.sourcepackagename import (
     ISourcePackageName,
     ISourcePackageNameSet,
 )
-from lp.services.database.sqlbase import SQLBase, cursor, sqlvalues
-from lp.services.database.sqlobject import (
-    SQLMultipleJoin,
-    SQLObjectNotFound,
-    StringCol,
-)
+from lp.services.database.interfaces import IStore
+from lp.services.database.sqlbase import cursor, sqlvalues
+from lp.services.database.stormbase import StormBase
 
 
 @implementer(ISourcePackageName)
-class SourcePackageName(SQLBase):
-    _table = "SourcePackageName"
+class SourcePackageName(StormBase):
+    __storm_table__ = "SourcePackageName"
 
-    name = StringCol(
-        dbName="name", notNull=True, unique=True, alternateID=True
-    )
+    id = Int(primary=True)
+    name = Unicode(name="name", allow_none=False)
 
-    potemplates = SQLMultipleJoin("POTemplate", joinColumn="sourcepackagename")
-    packagings = SQLMultipleJoin(
-        "Packaging", joinColumn="sourcepackagename", orderBy="Packaging.id"
-    )
+    def __init__(self, name):
+        super().__init__()
+        self.name = name
 
     def __str__(self):
         return self.name
@@ -44,46 +39,54 @@ class SourcePackageName(SQLBase):
     def __repr__(self):
         return "<%s '%s'>" % (self.__class__.__name__, self.name)
 
+    @classmethod
     def ensure(klass, name):
-        try:
-            return klass.byName(name)
-        except SQLObjectNotFound:
-            return klass(name=name)
-
-    ensure = classmethod(ensure)
+        spn = IStore(klass).find(klass, name=name).one()
+        if spn is None:
+            spn = klass(name=name)
+        return spn
 
 
 @implementer(ISourcePackageNameSet)
 class SourcePackageNameSet:
     def __getitem__(self, name):
         """See `ISourcePackageNameSet`."""
-        name = six.ensure_text(name, "ASCII")
-        try:
-            return SourcePackageName.byName(name)
-        except SQLObjectNotFound:
+        spn = (
+            IStore(SourcePackageName).find(SourcePackageName, name=name).one()
+        )
+        if spn is None:
             raise NoSuchSourcePackageName(name)
+        return spn
 
     def get(self, sourcepackagenameid):
         """See `ISourcePackageNameSet`."""
-        try:
-            return SourcePackageName.get(sourcepackagenameid)
-        except SQLObjectNotFound:
+        spn = IStore(SourcePackageName).get(
+            SourcePackageName, sourcepackagenameid
+        )
+        if spn is None:
             raise NotFoundError(sourcepackagenameid)
+        return spn
 
     def getAll(self):
         """See `ISourcePackageNameSet`."""
-        return SourcePackageName.select()
+        return IStore(SourcePackageName).find(SourcePackageName)
 
     def queryByName(self, name):
         """See `ISourcePackageNameSet`."""
-        return SourcePackageName.selectOneBy(name=name)
+        return (
+            IStore(SourcePackageName).find(SourcePackageName, name=name).one()
+        )
 
     def new(self, name):
         if not valid_name(name):
             raise InvalidName(
                 "%s is not a valid name for a source package." % name
             )
-        return SourcePackageName(name=name)
+        spn = SourcePackageName(name=name)
+        store = IStore(SourcePackageName)
+        store.add(spn)
+        store.flush()
+        return spn
 
     def getOrCreateByName(self, name):
         try:
diff --git a/lib/lp/registry/vocabularies.py b/lib/lp/registry/vocabularies.py
index e8932cd..955e975 100644
--- a/lib/lp/registry/vocabularies.py
+++ b/lib/lp/registry/vocabularies.py
@@ -2122,7 +2122,7 @@ class SourcePackageNameVocabulary(NamedStormHugeVocabulary):
         if not query:
             return self.emptySelectResults()
 
-        query = six.ensure_text(query).lower()
+        query = query.lower()
         results = IStore(self._table).find(
             self._table,
             Or(
diff --git a/lib/lp/soyuz/doc/gina-multiple-arch.rst b/lib/lp/soyuz/doc/gina-multiple-arch.rst
index 5f6c56b..6bcfd79 100644
--- a/lib/lp/soyuz/doc/gina-multiple-arch.rst
+++ b/lib/lp/soyuz/doc/gina-multiple-arch.rst
@@ -178,7 +178,11 @@ Check that the source package was correctly imported:
 
     >>> from lp.soyuz.model.binarypackagename import BinaryPackageName
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
-    >>> ekg_name = SourcePackageName.selectOneBy(name="ekg")
+    >>> ekg_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="ekg")
+    ...     .one()
+    ... )
     >>> ekg = (
     ...     IStore(SourcePackageRelease)
     ...     .find(
diff --git a/lib/lp/soyuz/doc/gina.rst b/lib/lp/soyuz/doc/gina.rst
index b48d787..1df68a2 100644
--- a/lib/lp/soyuz/doc/gina.rst
+++ b/lib/lp/soyuz/doc/gina.rst
@@ -245,12 +245,16 @@ forcefully (ubuntu-meta).
 Check that x11proto-damage has its Build-Depends-Indep value correctly set:
 
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
-    >>> n = SourcePackageName.selectOneBy(name="x11proto-damage")
+    >>> x11p_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="x11proto-damage")
+    ...     .one()
+    ... )
     >>> x11p = (
     ...     IStore(SourcePackageRelease)
     ...     .find(
     ...         SourcePackageRelease,
-    ...         sourcepackagename=n,
+    ...         sourcepackagename=x11p_name,
     ...         version="6.8.99.7-2",
     ...     )
     ...     .one()
@@ -302,10 +306,14 @@ Same for the copyright:
 Check that the dsc on the libcap package is correct, and that we
 only imported one:
 
-    >>> n = SourcePackageName.selectOneBy(name="libcap")
+    >>> cap_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="libcap")
+    ...     .one()
+    ... )
     >>> cap = (
     ...     IStore(SourcePackageRelease)
-    ...     .find(SourcePackageRelease, sourcepackagename=n)
+    ...     .find(SourcePackageRelease, sourcepackagename=cap_name)
     ...     .one()
     ... )
     >>> print(cap.dsc)
@@ -338,10 +346,18 @@ only imported one:
 
 Test ubuntu-meta in breezy, which was forcefully imported.
 
-    >>> n = SourcePackageName.selectOneBy(name="ubuntu-meta")
+    >>> um_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="ubuntu-meta")
+    ...     .one()
+    ... )
     >>> um = (
     ...     IStore(SourcePackageRelease)
-    ...     .find(SourcePackageRelease, sourcepackagename=n, version="0.80")
+    ...     .find(
+    ...         SourcePackageRelease,
+    ...         sourcepackagename=um_name,
+    ...         version="0.80",
+    ...     )
     ...     .one()
     ... )
     >>> print(
@@ -370,10 +386,14 @@ were calculated directly on the files):
 Check that the section on the python-pam package is correct, and that we
 only imported one:
 
-    >>> n = SourcePackageName.selectOneBy(name="python-pam")
+    >>> pp_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="python-pam")
+    ...     .one()
+    ... )
     >>> pp = (
     ...     IStore(SourcePackageRelease)
-    ...     .find(SourcePackageRelease, sourcepackagename=n)
+    ...     .find(SourcePackageRelease, sourcepackagename=pp_name)
     ...     .one()
     ... )
     >>> print(pp.component.name)
@@ -387,10 +407,14 @@ this is cut up correctly:
 
 Make sure that we only imported one db1-compat source package.
 
-    >>> n = SourcePackageName.selectOneBy(name="db1-compat")
+    >>> db1_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="db1-compat")
+    ...     .one()
+    ... )
     >>> db1 = (
     ...     IStore(SourcePackageRelease)
-    ...     .find(SourcePackageRelease, sourcepackagename=n)
+    ...     .find(SourcePackageRelease, sourcepackagename=db1_name)
     ...     .one()
     ... )
     >>> print(db1.section.name)
@@ -469,14 +493,14 @@ Check that the shlibs parsing and bin-only-NMU version handling works as
 expected:
 
     >>> from lp.soyuz.model.binarypackagename import BinaryPackageName
-    >>> n = (
+    >>> rio_name = (
     ...     IStore(BinaryPackageName)
     ...     .find(BinaryPackageName, name="rioutil")
     ...     .one()
     ... )
     >>> rio = (
     ...     IStore(BinaryPackageRelease)
-    ...     .find(BinaryPackageRelease, binarypackagename=n)
+    ...     .find(BinaryPackageRelease, binarypackagename=rio_name)
     ...     .one()
     ... )
     >>> print(rio.shlibdeps)
@@ -489,10 +513,12 @@ expected:
 Test all the data got to the ed BPR intact, and that the missing
 priority was correctly munged to "extra":
 
-    >>> n = IStore(BinaryPackageName).find(BinaryPackageName, name="ed").one()
+    >>> ed_name = (
+    ...     IStore(BinaryPackageName).find(BinaryPackageName, name="ed").one()
+    ... )
     >>> ed = (
     ...     IStore(BinaryPackageRelease)
-    ...     .find(BinaryPackageRelease, binarypackagename=n)
+    ...     .find(BinaryPackageRelease, binarypackagename=ed_name)
     ...     .one()
     ... )
     >>> print(ed.version)
@@ -527,7 +553,7 @@ We now check if the Breezy publication record has the correct priority:
 Check binary package libgjc-dev in Breezy. Its version number must differ from
 its source version number.
 
-    >>> n = (
+    >>> lib_name = (
     ...     IStore(BinaryPackageName)
     ...     .find(BinaryPackageName, name="libgcj-dev")
     ...     .one()
@@ -535,7 +561,9 @@ its source version number.
     >>> lib = (
     ...     IStore(BinaryPackageRelease)
     ...     .find(
-    ...         BinaryPackageRelease, binarypackagename=n, version="4:4.0.1-3"
+    ...         BinaryPackageRelease,
+    ...         binarypackagename=lib_name,
+    ...         version="4:4.0.1-3",
     ...     )
     ...     .one()
     ... )
@@ -548,14 +576,18 @@ its source version number.
 
 Check if the udeb was properly parsed and identified:
 
-    >>> n = (
+    >>> ac_name = (
     ...     IStore(BinaryPackageName)
     ...     .find(BinaryPackageName, name="archive-copier")
     ...     .one()
     ... )
     >>> ac = (
     ...     IStore(BinaryPackageRelease)
-    ...     .find(BinaryPackageRelease, binarypackagename=n, version="0.1.5")
+    ...     .find(
+    ...         BinaryPackageRelease,
+    ...         binarypackagename=ac_name,
+    ...         version="0.1.5",
+    ...     )
     ...     .one()
     ... )
     >>> print(ac.version)
@@ -573,7 +605,7 @@ Check if the udeb was properly parsed and identified:
 
 We check that the binary package publishing override facility works:
 
-    >>> n = (
+    >>> db1_name = (
     ...     IStore(BinaryPackageName)
     ...     .find(BinaryPackageName, name="libdb1-compat")
     ...     .one()
@@ -581,7 +613,9 @@ We check that the binary package publishing override facility works:
     >>> db1 = (
     ...     IStore(BinaryPackageRelease)
     ...     .find(
-    ...         BinaryPackageRelease, binarypackagename=n, version="2.1.3-7"
+    ...         BinaryPackageRelease,
+    ...         binarypackagename=db1_name,
+    ...         version="2.1.3-7",
     ...     )
     ...     .one()
     ... )
@@ -774,10 +808,18 @@ package -- that's what overrides actually do.
     ... )
     >>> print(ed_pub.priority)
     Extra
-    >>> n = SourcePackageName.selectOneBy(name="archive-copier")
+    >>> ac_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="archive-copier")
+    ...     .one()
+    ... )
     >>> ac = (
     ...     IStore(SourcePackageRelease)
-    ...     .find(SourcePackageRelease, sourcepackagename=n, version="0.3.6")
+    ...     .find(
+    ...         SourcePackageRelease,
+    ...         sourcepackagename=ac_name,
+    ...         version="0.3.6",
+    ...     )
     ...     .one()
     ... )
     >>> ac_pub = (
diff --git a/lib/lp/soyuz/doc/package-meta-classes.rst b/lib/lp/soyuz/doc/package-meta-classes.rst
index 62cc13b..5e479b0 100644
--- a/lib/lp/soyuz/doc/package-meta-classes.rst
+++ b/lib/lp/soyuz/doc/package-meta-classes.rst
@@ -26,7 +26,11 @@ Combining Distribution and SourcePackageRelease:
     >>> print(distribution.name)
     ubuntu
 
-    >>> src_name = SourcePackageName.selectOneBy(name="pmount")
+    >>> src_name = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="pmount")
+    ...     .one()
+    ... )
     >>> print(src_name.name)
     pmount
 
diff --git a/lib/lp/soyuz/doc/sourcepackagerelease.rst b/lib/lp/soyuz/doc/sourcepackagerelease.rst
index f68e146..077d746 100644
--- a/lib/lp/soyuz/doc/sourcepackagerelease.rst
+++ b/lib/lp/soyuz/doc/sourcepackagerelease.rst
@@ -238,7 +238,11 @@ kilo-bytes).
 Verify that empty packages have a size of zero.
 
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
-    >>> linux_src = SourcePackageName.selectOneBy(name="linux-source-2.6.15")
+    >>> linux_src = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="linux-source-2.6.15")
+    ...     .one()
+    ... )
     >>> spr = (
     ...     IStore(SourcePackageRelease)
     ...     .find(
diff --git a/lib/lp/soyuz/doc/soyuz-upload.rst b/lib/lp/soyuz/doc/soyuz-upload.rst
index 9413550..fe2edbd 100644
--- a/lib/lp/soyuz/doc/soyuz-upload.rst
+++ b/lib/lp/soyuz/doc/soyuz-upload.rst
@@ -328,7 +328,11 @@ Let's check if packages were uploaded correctly.
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
     >>> from lp.services.database.interfaces import IStore
     >>> from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
-    >>> spn = SourcePackageName.selectOneBy(name="drdsl")
+    >>> spn = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="drdsl")
+    ...     .one()
+    ... )
     >>> print(spn.name)
     drdsl
     >>> spr = (
@@ -364,7 +368,11 @@ Let's check if packages were uploaded correctly.
 
 Same thing for etherwake:
 
-    >>> spn = SourcePackageName.selectOneBy(name="etherwake")
+    >>> spn = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="etherwake")
+    ...     .one()
+    ... )
     >>> print(spn.name)
     etherwake
     >>> spr = (
@@ -434,7 +442,11 @@ as NEW and RELEASE.
     >>> from lp.soyuz.model.queue import PackageUploadSource
     >>> for name in package_names:
     ...     print(name)
-    ...     spn = SourcePackageName.selectOneBy(name=name)
+    ...     spn = (
+    ...         IStore(SourcePackageName)
+    ...         .find(SourcePackageName, name=name)
+    ...         .one()
+    ...     )
     ...     spr = (
     ...         IStore(SourcePackageRelease)
     ...         .find(SourcePackageRelease, sourcepackagename=spn)
@@ -508,7 +520,11 @@ These packages must now be in the publishing history. Let's check it.
     ... )
     >>> package_names.sort()
     >>> for name in package_names:
-    ...     spn = SourcePackageName.selectOneBy(name=name)
+    ...     spn = (
+    ...         IStore(SourcePackageName)
+    ...         .find(SourcePackageName, name=name)
+    ...         .one()
+    ...     )
     ...     spr = (
     ...         IStore(SourcePackageRelease)
     ...         .find(SourcePackageRelease, sourcepackagename=spn)
diff --git a/lib/lp/soyuz/model/distroseriesdifferencejob.py b/lib/lp/soyuz/model/distroseriesdifferencejob.py
index d1e73f5..6b1faae 100644
--- a/lib/lp/soyuz/model/distroseriesdifferencejob.py
+++ b/lib/lp/soyuz/model/distroseriesdifferencejob.py
@@ -271,7 +271,9 @@ class DistroSeriesDifferenceJob(DistributionJobDerived):
 
     @property
     def sourcepackagename(self):
-        return SourcePackageName.get(self.metadata["sourcepackagename"])
+        return IStore(SourcePackageName).get(
+            SourcePackageName, self.metadata["sourcepackagename"]
+        )
 
     @property
     def derived_series(self):
diff --git a/lib/lp/soyuz/scripts/gina/handlers.py b/lib/lp/soyuz/scripts/gina/handlers.py
index 37ae1f7..ead42ee 100644
--- a/lib/lp/soyuz/scripts/gina/handlers.py
+++ b/lib/lp/soyuz/scripts/gina/handlers.py
@@ -40,7 +40,6 @@ from lp.registry.model.distroseries import DistroSeries
 from lp.registry.model.sourcepackagename import SourcePackageName
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.interfaces import IStore
-from lp.services.database.sqlobject import SQLObjectNotFound
 from lp.services.librarian.interfaces import ILibraryFileAliasSet
 from lp.services.scripts import log
 from lp.soyuz.enums import (
@@ -592,9 +591,12 @@ class SourcePackageHandler:
 
         Returns the sourcepackagerelease if exists or none if not.
         """
-        try:
-            spname = SourcePackageName.byName(source)
-        except SQLObjectNotFound:
+        spname = (
+            IStore(SourcePackageName)
+            .find(SourcePackageName, name=source)
+            .one()
+        )
+        if spname is None:
             return None
 
         # Check if this sourcepackagerelease already exists using name and
diff --git a/lib/lp/translations/doc/poexport-language-pack.rst b/lib/lp/translations/doc/poexport-language-pack.rst
index 996cccd..58db4bc 100644
--- a/lib/lp/translations/doc/poexport-language-pack.rst
+++ b/lib/lp/translations/doc/poexport-language-pack.rst
@@ -116,6 +116,7 @@ some DB classes.
     >>> from lp.registry.interfaces.distribution import IDistributionSet
     >>> from lp.registry.interfaces.person import IPersonSet
     >>> from lp.registry.model.sourcepackagename import SourcePackageName
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.translations.model.potemplate import POTemplate
 
 Get hold of a person.
@@ -130,7 +131,11 @@ Get the Grumpy distro series.
 
 Get a source package name to go with our distro series.
 
-    >>> spn = SourcePackageName.byName("evolution")
+    >>> spn = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="evolution")
+    ...     .one()
+    ... )
 
 Put a dummy file in the Librarian required by the new template we are
 creating.
diff --git a/lib/lp/translations/doc/translationimportqueue.rst b/lib/lp/translations/doc/translationimportqueue.rst
index e8f0793..29dabee 100644
--- a/lib/lp/translations/doc/translationimportqueue.rst
+++ b/lib/lp/translations/doc/translationimportqueue.rst
@@ -112,7 +112,9 @@ Now let's try the same against the evolution sourcepackage that only has an
 IPOTemplate.
 
     >>> hoary_distroseries = DistroSeries.get(3)
-    >>> evolution_sourcepackagename = SourcePackageName.get(9)
+    >>> evolution_sourcepackagename = IStore(SourcePackageName).get(
+    ...     SourcePackageName, 9
+    ... )
     >>> entry = translationimportqueue.addOrUpdateEntry(
     ...     "po/sr.po",
     ...     b"foo",
diff --git a/lib/lp/translations/doc/translationsoverview.rst b/lib/lp/translations/doc/translationsoverview.rst
index 818af4c..9b4a70c 100644
--- a/lib/lp/translations/doc/translationsoverview.rst
+++ b/lib/lp/translations/doc/translationsoverview.rst
@@ -162,7 +162,11 @@ list as well.
 
     >>> start_karma_update()
     >>> ubuntu = getUtility(IDistributionSet).getByName("ubuntu")
-    >>> evolution_sourcepackagename = SourcePackageName.byName("evolution")
+    >>> evolution_sourcepackagename = (
+    ...     IStore(SourcePackageName)
+    ...     .find(SourcePackageName, name="evolution")
+    ...     .one()
+    ... )
     >>> cache_entry = karmacachemanager.new(
     ...     5150,
     ...     carlos.id,
diff --git a/lib/lp/translations/tests/test_autoapproval.py b/lib/lp/translations/tests/test_autoapproval.py
index eeadbb0..d1e6c51 100644
--- a/lib/lp/translations/tests/test_autoapproval.py
+++ b/lib/lp/translations/tests/test_autoapproval.py
@@ -24,7 +24,7 @@ from lp.registry.model.sourcepackagename import (
     SourcePackageName,
     SourcePackageNameSet,
 )
-from lp.services.database.interfaces import IPrimaryStore
+from lp.services.database.interfaces import IPrimaryStore, IStore
 from lp.services.worlddata.interfaces.language import ILanguageSet
 from lp.testing import TestCaseWithFactory, verifyObject
 from lp.testing.fakemethod import FakeMethod
@@ -87,7 +87,11 @@ class TestCustomLanguageCode(TestCaseWithFactory):
         )
 
         self.distro = Distribution.byName("ubuntu")
-        self.sourcepackagename = SourcePackageName.byName("evolution")
+        self.sourcepackagename = (
+            IStore(SourcePackageName)
+            .find(SourcePackageName, name="evolution")
+            .one()
+        )
         self.package_codes["Brazilian"] = CustomLanguageCode(
             translation_target=self.distro.getSourcePackage(
                 self.sourcepackagename
@@ -118,7 +122,11 @@ class TestCustomLanguageCode(TestCaseWithFactory):
         brazilian = gentoo_package.getCustomLanguageCode("Brazilian")
         self.assertEqual(brazilian, None)
 
-        cnews = SourcePackageName.byName("cnews")
+        cnews = (
+            IStore(SourcePackageName)
+            .find(SourcePackageName, name="cnews")
+            .one()
+        )
         cnews_package = self.distro.getSourcePackage(cnews)
         self.assertEqual(cnews_package.getCustomLanguageCode("nocode"), None)
         self.assertEqual(