← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Convert LibraryFile{Alias,Content} queries to Storm

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

`LibraryFileAlias` and `LibraryFileContent` are used all over the place, so converting them all to the Storm style in one go results in a rather large diff.  These queries can be converted in advance to make review easier.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:stormify-libraryfile-queries into launchpad:master.
diff --git a/cronscripts/parse-librarian-apache-access-logs.py b/cronscripts/parse-librarian-apache-access-logs.py
index 935f12e..1a724b5 100755
--- a/cronscripts/parse-librarian-apache-access-logs.py
+++ b/cronscripts/parse-librarian-apache-access-logs.py
@@ -16,9 +16,9 @@ updating the counts of every LFA, in order to get through the backlog.
 
 import _pythonpath  # noqa: F401
 
-from storm.sqlobject import SQLObjectNotFound
 from zope.component import getUtility
 
+from lp.app.errors import NotFoundError
 from lp.services.apachelogparser.script import ParseApacheLogs
 from lp.services.config import config
 from lp.services.librarian.interfaces import ILibraryFileAliasSet
@@ -47,10 +47,11 @@ class ParseLibrarianApacheLogs(ParseApacheLogs):
     def getDownloadCountUpdater(self, file_id):
         """See `ParseApacheLogs`."""
         try:
-            return self.libraryfilealias_set[file_id].updateDownloadCount
-        except SQLObjectNotFound:
-            # This file has been deleted from the librarian, so don't
-            # try to store download counters for it.
+            return self.libraryfilealias_set[int(file_id)].updateDownloadCount
+        except (ValueError, NotFoundError):
+            # Either this isn't a valid file ID or this file has been
+            # deleted from the librarian, so don't try to store download
+            # counters for it.
             return None
 
 
diff --git a/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py b/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py
index 1b27830..f163b4f 100644
--- a/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py
+++ b/lib/lp/archiveuploader/tests/test_nascentupload_documentation.py
@@ -12,6 +12,7 @@ from lp.archiveuploader.nascentupload import NascentUpload
 from lp.archiveuploader.tests import datadir, getPolicy
 from lp.archiveuploader.uploadpolicy import ArchiveUploadType
 from lp.registry.interfaces.distribution import IDistributionSet
+from lp.services.database.interfaces import IStore
 from lp.services.librarian.model import LibraryFileAlias
 from lp.services.log.logger import DevNullLogger
 from lp.soyuz.interfaces.component import IComponentSet
@@ -76,7 +77,7 @@ def prepareHoaryForUploads(test):
     ComponentSelection(distroseries=hoary, component=universe)
 
     # Create a fake hoary/i386 chroot.
-    fake_chroot = LibraryFileAlias.get(1)
+    fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1)
     hoary["i386"].addOrUpdateChroot(fake_chroot)
 
     LaunchpadZopelessLayer.txn.commit()
diff --git a/lib/lp/registry/model/person.py b/lib/lp/registry/model/person.py
index 8aef249..3dea058 100644
--- a/lib/lp/registry/model/person.py
+++ b/lib/lp/registry/model/person.py
@@ -234,7 +234,7 @@ from lp.services.identity.interfaces.emailaddress import (
 )
 from lp.services.identity.model.account import Account
 from lp.services.identity.model.emailaddress import EmailAddress, HasOwnerMixin
-from lp.services.librarian.model import LibraryFileAlias
+from lp.services.librarian.model import LibraryFileAlias, LibraryFileContent
 from lp.services.mail.helpers import (
     get_contact_email_addresses,
     get_email_template,
@@ -4603,9 +4603,10 @@ class PersonSet:
             return
         # Listify, since this is a pure cache.
         list(
-            LibraryFileAlias.select(
-                "LibraryFileAlias.id IN %s" % sqlvalues(aliases),
-                prejoins=["content"],
+            IStore(LibraryFileAlias).find(
+                (LibraryFileAlias, LibraryFileContent),
+                LibraryFileAlias.id.is_in(aliases),
+                LibraryFileAlias.content == LibraryFileContent.id,
             )
         )
 
diff --git a/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst b/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst
index 867b8aa..b411b02 100644
--- a/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst
+++ b/lib/lp/registry/stories/productrelease/xx-productrelease-view.rst
@@ -41,9 +41,12 @@ downloaded and the date of the last download on that table as well.
     # Manually update the download counter for that file above so that we can
     # test it.
     >>> from datetime import date, datetime, timezone
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.services.librarian.model import LibraryFileAlias
-    >>> lfa = LibraryFileAlias.selectOne(
-    ...     LibraryFileAlias.q.filename == "firefox_0.9.2.orig.tar.gz"
+    >>> lfa = (
+    ...     IStore(LibraryFileAlias)
+    ...     .find(LibraryFileAlias, filename="firefox_0.9.2.orig.tar.gz")
+    ...     .one()
     ... )
     >>> lfa.updateDownloadCount(date(2006, 5, 4), None, 1)
 
diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
index c8a803e..b3c8ad7 100644
--- a/lib/lp/services/librarian/client.py
+++ b/lib/lp/services/librarian/client.py
@@ -28,9 +28,8 @@ from storm.store import Store
 from zope.interface import implementer
 
 from lp.services.config import config, dbconfig
-from lp.services.database.interfaces import IPrimaryStore
+from lp.services.database.interfaces import IPrimaryStore, IStore
 from lp.services.database.postgresql import ConnectionString
-from lp.services.database.sqlobject import SQLObjectNotFound
 from lp.services.librarian.interfaces.client import (
     LIBRARIAN_SERVER_DEFAULT_TIMEOUT,
     DownloadFailed,
@@ -410,10 +409,7 @@ class FileDownloadClient:
         """
         from lp.services.librarian.model import LibraryFileAlias
 
-        try:
-            lfa = LibraryFileAlias.get(aliasID)
-        except SQLObjectNotFound:
-            lfa = None
+        lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, aliasID)
 
         if lfa is None:
             raise DownloadFailed("Alias %d not found" % aliasID)
diff --git a/lib/lp/services/librarian/model.py b/lib/lp/services/librarian/model.py
index 83ca952..9c517c5 100644
--- a/lib/lp/services/librarian/model.py
+++ b/lib/lp/services/librarian/model.py
@@ -19,6 +19,7 @@ from storm.locals import Date, Desc, Int, Reference, ReferenceSet, Store
 from zope.component import adapter, getUtility
 from zope.interface import Interface, implementer
 
+from lp.app.errors import NotFoundError
 from lp.registry.errors import InvalidFilename
 from lp.services.config import config
 from lp.services.database.constants import DEFAULT, UTC_NOW
@@ -278,17 +279,17 @@ class LibraryFileAliasSet:
 
     def __getitem__(self, key):
         """See ILibraryFileAliasSet.__getitem__"""
-        return LibraryFileAlias.get(key)
+        lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, key)
+        if lfa is None:
+            raise NotFoundError(key)
+        return lfa
 
     def findBySHA256(self, sha256):
         """See ILibraryFileAliasSet."""
-        return LibraryFileAlias.select(
-            """
-            content = LibraryFileContent.id
-            AND LibraryFileContent.sha256 = '%s'
-            """
-            % sha256,
-            clauseTables=["LibraryFileContent"],
+        return IStore(LibraryFileAlias).find(
+            LibraryFileAlias,
+            LibraryFileAlias.content == LibraryFileContent.id,
+            LibraryFileContent.sha256 == sha256,
         )
 
     def preloadLastDownloaded(self, lfas):
diff --git a/lib/lp/services/librarian/tests/test_client.py b/lib/lp/services/librarian/tests/test_client.py
index 39f6ee8..012d1e1 100644
--- a/lib/lp/services/librarian/tests/test_client.py
+++ b/lib/lp/services/librarian/tests/test_client.py
@@ -20,7 +20,7 @@ from testtools.testcase import ExpectedException
 
 from lp.services.config import config
 from lp.services.daemons.tachandler import TacTestSetup
-from lp.services.database.interfaces import IStandbyStore
+from lp.services.database.interfaces import IStandbyStore, IStore
 from lp.services.database.policy import StandbyDatabasePolicy
 from lp.services.database.sqlbase import block_implicit_flushes
 from lp.services.librarian import client as client_module
@@ -387,8 +387,9 @@ class LibrarianClientTestCase(TestCase):
         sha256 = hashlib.sha256(data).hexdigest()
 
         client = LibrarianClient()
-        lfa = LibraryFileAlias.get(
-            client.addFile("file", len(data), io.BytesIO(data), "text/plain")
+        lfa = IStore(LibraryFileAlias).get(
+            LibraryFileAlias,
+            client.addFile("file", len(data), io.BytesIO(data), "text/plain"),
         )
 
         self.assertEqual(md5, lfa.content.md5)
@@ -427,7 +428,7 @@ class LibrarianClientTestCase(TestCase):
                 "expected %s to start with %s" % (download_url, expected_host),
             )
             # If the alias has been deleted, _getURLForDownload returns None.
-            lfa = LibraryFileAlias.get(alias_id)
+            lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, alias_id)
             lfa.content = None
             call = block_implicit_flushes(  # Prevent a ProgrammingError
                 LibrarianClient._getURLForDownload
@@ -469,7 +470,7 @@ class LibrarianClientTestCase(TestCase):
                 "expected %s to start with %s" % (download_url, expected_host),
             )
             # If the alias has been deleted, _getURLForDownload returns None.
-            lfa = LibraryFileAlias.get(alias_id)
+            lfa = IStore(LibraryFileAlias).get(LibraryFileAlias, alias_id)
             lfa.content = None
             call = block_implicit_flushes(  # Prevent a ProgrammingError
                 RestrictedLibrarianClient._getURLForDownload
diff --git a/lib/lp/services/librarianserver/db.py b/lib/lp/services/librarianserver/db.py
index b747c2c..1ffc2f6 100644
--- a/lib/lp/services/librarianserver/db.py
+++ b/lib/lp/services/librarianserver/db.py
@@ -49,7 +49,12 @@ class Library:
     # The following methods are read-only queries.
 
     def lookupBySHA1(self, digest):
-        return [fc.id for fc in LibraryFileContent.selectBy(sha1=digest)]
+        return [
+            fc.id
+            for fc in IStore(LibraryFileContent).find(
+                LibraryFileContent, sha1=digest
+            )
+        ]
 
     @defer.inlineCallbacks
     def _verifyMacaroon(self, macaroon, aliasid):
diff --git a/lib/lp/services/librarianserver/testing/server.py b/lib/lp/services/librarianserver/testing/server.py
index c2ef75b..26a7914 100644
--- a/lib/lp/services/librarianserver/testing/server.py
+++ b/lib/lp/services/librarianserver/testing/server.py
@@ -19,6 +19,7 @@ from fixtures import Fixture, FunctionFixture
 
 from lp.services.config import config
 from lp.services.daemons.tachandler import TacException, TacTestSetup
+from lp.services.database.interfaces import IStore
 from lp.services.librarian.model import LibraryFileContent
 from lp.services.librarianserver.storage import _relFileLocation
 from lp.services.osutils import get_pid_from_file
@@ -255,7 +256,7 @@ class LibrarianServerFixture(TacTestSetup):
 def fillLibrarianFile(fileid, content=None):
     """Write contents in disk for a librarian sampledata."""
     with dbuser("librariangc"):
-        lfc = LibraryFileContent.get(fileid)
+        lfc = IStore(LibraryFileContent).get(LibraryFileContent, fileid)
         if content is None:
             content = b"x" * lfc.filesize
         else:
diff --git a/lib/lp/services/librarianserver/tests/test_gc.py b/lib/lp/services/librarianserver/tests/test_gc.py
index 41087cc..0d2a163 100644
--- a/lib/lp/services/librarianserver/tests/test_gc.py
+++ b/lib/lp/services/librarianserver/tests/test_gc.py
@@ -22,13 +22,12 @@ from swiftclient import client as swiftclient
 from testtools.matchers import AnyMatch, Equals, MatchesListwise, MatchesRegex
 
 from lp.services.config import config
-from lp.services.database.interfaces import IPrimaryStore
+from lp.services.database.interfaces import IStore
 from lp.services.database.sqlbase import (
     ISOLATION_LEVEL_AUTOCOMMIT,
     connect,
     cursor,
 )
-from lp.services.database.sqlobject import SQLObjectNotFound
 from lp.services.features.testing import FeatureFixture
 from lp.services.librarian.client import LibrarianClient
 from lp.services.librarian.model import LibraryFileAlias, LibraryFileContent
@@ -50,6 +49,7 @@ class TestLibrarianGarbageCollectionBase:
 
     def setUp(self):
         super().setUp()
+        self.store = IStore(LibraryFileContent)
         self.client = LibrarianClient()
         self.patch(librariangc, "log", BufferLogger())
 
@@ -74,8 +74,7 @@ class TestLibrarianGarbageCollectionBase:
         # Make sure that every file the database knows about exists on disk.
         # We manually remove them for tests that need to cope with missing
         # library items.
-        store = IPrimaryStore(LibraryFileContent)
-        for content in store.find(LibraryFileContent):
+        for content in self.store.find(LibraryFileContent):
             path = librariangc.get_file_path(content.id)
             if not os.path.exists(path):
                 if not os.path.exists(os.path.dirname(path)):
@@ -121,14 +120,14 @@ class TestLibrarianGarbageCollectionBase:
             io.BytesIO(content),
             "text/plain",
         )
-        f1 = LibraryFileAlias.get(f1_id)
+        f1 = self.store.get(LibraryFileAlias, f1_id)
         f2_id = self.client.addFile(
             "foo.txt",
             len(content),
             io.BytesIO(content),
             "text/plain",
         )
-        f2 = LibraryFileAlias.get(f2_id)
+        f2 = self.store.get(LibraryFileAlias, f2_id)
 
         # Make sure the duplicates really are distinct
         self.assertNotEqual(f1_id, f2_id)
@@ -165,16 +164,16 @@ class TestLibrarianGarbageCollectionBase:
 
         # Confirm that the duplicates have been merged
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
-        f2 = LibraryFileAlias.get(self.f2_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
+        f2 = self.store.get(LibraryFileAlias, self.f2_id)
         self.assertEqual(f1.contentID, f2.contentID)
 
     def test_DeleteUnreferencedAliases(self):
         self.ztm.begin()
 
         # Confirm that our sample files are there.
-        f1 = LibraryFileAlias.get(self.f1_id)
-        f2 = LibraryFileAlias.get(self.f2_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
+        f2 = self.store.get(LibraryFileAlias, self.f2_id)
         # Grab the content IDs related to these
         # unreferenced LibraryFileAliases
         c1_id = f1.contentID
@@ -188,13 +187,13 @@ class TestLibrarianGarbageCollectionBase:
         # This should have committed
         self.ztm.begin()
 
-        # Confirm that the LibaryFileContents are still there.
-        LibraryFileContent.get(c1_id)
-        LibraryFileContent.get(c2_id)
+        # Confirm that the LibraryFileContents are still there.
+        self.assertIsNotNone(self.store.get(LibraryFileContent, c1_id))
+        self.assertIsNotNone(self.store.get(LibraryFileContent, c2_id))
 
         # But the LibraryFileAliases should be gone
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id)
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id)
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id))
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id))
 
     def test_DeleteUnreferencedAliases2(self):
         # Don't delete LibraryFileAliases accessed recently
@@ -205,8 +204,8 @@ class TestLibrarianGarbageCollectionBase:
 
         # We now have two aliases sharing the same content.
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
-        f2 = LibraryFileAlias.get(self.f2_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
+        f2 = self.store.get(LibraryFileAlias, self.f2_id)
         self.assertEqual(f1.content, f2.content)
 
         # Flag one of our LibraryFileAliases as being recently created
@@ -222,8 +221,8 @@ class TestLibrarianGarbageCollectionBase:
         librariangc.delete_unreferenced_aliases(self.con)
 
         self.ztm.begin()
-        LibraryFileAlias.get(self.f1_id)
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id)
+        self.assertIsNotNone(self.store.get(LibraryFileAlias, self.f1_id))
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id))
 
     def test_DeleteUnreferencedAndWellExpiredAliases(self):
         # LibraryFileAliases can be removed after they have expired
@@ -234,7 +233,7 @@ class TestLibrarianGarbageCollectionBase:
 
         # Flag one of our LibraryFileAliases with an expiry date in the past
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         f1.expires = self.ancient_past
         del f1
         self.ztm.commit()
@@ -246,8 +245,8 @@ class TestLibrarianGarbageCollectionBase:
 
         # Make sure both our example files are gone
         self.ztm.begin()
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id)
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id)
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id))
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id))
 
     def test_DoneDeleteUnreferencedButNotExpiredAliases(self):
         # LibraryFileAliases can be removed only after they have expired.
@@ -261,7 +260,7 @@ class TestLibrarianGarbageCollectionBase:
         # Flag one of our LibraryFileAliases with an expiry date in the
         # recent past.
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         f1.expires = self.recent_past
         del f1
         self.ztm.commit()
@@ -274,7 +273,7 @@ class TestLibrarianGarbageCollectionBase:
         # Make sure both our example files are still there
         self.ztm.begin()
         # Our recently expired LibraryFileAlias is still available.
-        LibraryFileAlias.get(self.f1_id)
+        self.assertIsNotNone(self.store.get(LibraryFileAlias, self.f1_id))
 
     def test_deleteWellExpiredAliases(self):
         # LibraryFileAlias records that are expired are unlinked from their
@@ -282,7 +281,7 @@ class TestLibrarianGarbageCollectionBase:
 
         # Flag one of our LibraryFileAliases with an expiry date in the past
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         f1.expires = self.ancient_past
         del f1
         self.ztm.commit()
@@ -292,10 +291,10 @@ class TestLibrarianGarbageCollectionBase:
 
         self.ztm.begin()
         # Make sure the well expired f1 is still there, but has no content.
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         self.assertIsNone(f1.content)
         # f2 should still have content, as it isn't flagged for expiry.
-        f2 = LibraryFileAlias.get(self.f2_id)
+        f2 = self.store.get(LibraryFileAlias, self.f2_id)
         self.assertIsNotNone(f2.content)
 
     def test_ignoreRecentlyExpiredAliases(self):
@@ -305,7 +304,7 @@ class TestLibrarianGarbageCollectionBase:
         # Flag one of our LibraryFileAliases with an expiry date in the
         # recent past.
         self.ztm.begin()
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         f1.expires = self.recent_past  # Within stay of execution.
         del f1
         self.ztm.commit()
@@ -316,10 +315,10 @@ class TestLibrarianGarbageCollectionBase:
         self.ztm.begin()
         # Make sure f1 is still there and has content. This ensures that
         # our stay of execution is still working.
-        f1 = LibraryFileAlias.get(self.f1_id)
+        f1 = self.store.get(LibraryFileAlias, self.f1_id)
         self.assertIsNotNone(f1.content)
         # f2 should still have content, as it isn't flagged for expiry.
-        f2 = LibraryFileAlias.get(self.f2_id)
+        f2 = self.store.get(LibraryFileAlias, self.f2_id)
         self.assertIsNotNone(f2.content)
 
     def test_DeleteUnreferencedContent(self):
@@ -583,11 +582,11 @@ class TestLibrarianGarbageCollectionBase:
 
         # Make sure that our example files have been garbage collected
         self.ztm.begin()
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f1_id)
-        self.assertRaises(SQLObjectNotFound, LibraryFileAlias.get, self.f2_id)
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f1_id))
+        self.assertIsNone(self.store.get(LibraryFileAlias, self.f2_id))
 
         # And make sure stuff that *is* referenced remains
-        LibraryFileAlias.get(2)
+        self.assertIsNotNone(self.store.get(LibraryFileAlias, 2))
         cur = cursor()
         cur.execute("SELECT count(*) FROM LibraryFileAlias")
         count = cur.fetchone()[0]
@@ -625,19 +624,21 @@ class TestDiskLibrarianGarbageCollection(
         # original file, ignoring the extension.
         switch_dbuser("testadmin")
         content = b"foo"
-        lfa = LibraryFileAlias.get(
+        lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "foo.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         id_aborted = lfa.contentID
         # Roll back the database changes, leaving the file on disk.
         transaction.abort()
 
-        lfa = LibraryFileAlias.get(
+        lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "bar.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         transaction.commit()
         id_committed = lfa.contentID
@@ -811,17 +812,19 @@ class TestSwiftLibrarianGarbageCollection(
         # by a manifest. GC treats the segments like the original file.
         switch_dbuser("testadmin")
         content = b"uploading to swift bigly"
-        big1_lfa = LibraryFileAlias.get(
+        big1_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "foo.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         big1_id = big1_lfa.contentID
 
-        big2_lfa = LibraryFileAlias.get(
+        big2_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "bar.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         big2_id = big2_lfa.contentID
         transaction.commit()
@@ -872,17 +875,19 @@ class TestSwiftLibrarianGarbageCollection(
         # suggest that it might happen.
         switch_dbuser("testadmin")
         content = b"uploading to swift"
-        f1_lfa = LibraryFileAlias.get(
+        f1_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "foo.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         f1_id = f1_lfa.contentID
 
-        f2_lfa = LibraryFileAlias.get(
+        f2_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "bar.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         f2_id = f2_lfa.contentID
         transaction.commit()
@@ -937,17 +942,19 @@ class TestSwiftLibrarianGarbageCollection(
         # to delete it.  It's not clear why this happens in practice.
         switch_dbuser("testadmin")
         content = b"uploading to swift"
-        f1_lfa = LibraryFileAlias.get(
+        f1_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "foo.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         f1_id = f1_lfa.contentID
 
-        f2_lfa = LibraryFileAlias.get(
+        f2_lfa = self.store.get(
+            LibraryFileAlias,
             self.client.addFile(
                 "bar.txt", len(content), io.BytesIO(content), "text/plain"
-            )
+            ),
         )
         f2_id = f2_lfa.contentID
         transaction.commit()
@@ -1017,10 +1024,11 @@ class TestTwoSwiftsLibrarianGarbageCollection(
         switch_dbuser("testadmin")
         content = b"foo"
         lfas = [
-            LibraryFileAlias.get(
+            self.store.get(
+                LibraryFileAlias,
                 self.client.addFile(
                     "foo.txt", len(content), io.BytesIO(content), "text/plain"
-                )
+                ),
             )
             for _ in range(12)
         ]
@@ -1103,10 +1111,11 @@ class TestTwoSwiftsLibrarianGarbageCollection(
         switch_dbuser("testadmin")
         content = b"foo"
         lfas = [
-            LibraryFileAlias.get(
+            self.store.get(
+                LibraryFileAlias,
                 self.client.addFile(
                     "foo.txt", len(content), io.BytesIO(content), "text/plain"
-                )
+                ),
             )
             for _ in range(12)
         ]
diff --git a/lib/lp/services/librarianserver/tests/test_storage.py b/lib/lp/services/librarianserver/tests/test_storage.py
index c95d4f8..f5100a1 100644
--- a/lib/lp/services/librarianserver/tests/test_storage.py
+++ b/lib/lp/services/librarianserver/tests/test_storage.py
@@ -105,7 +105,7 @@ class LibrarianStorageTestCase(unittest.TestCase):
         newfile = self.storage.startAddFile("file", len(data))
         newfile.append(data)
         lfc_id, lfa_id = newfile.store()
-        lfc = LibraryFileContent.get(lfc_id)
+        lfc = self.store.get(LibraryFileContent, lfc_id)
         self.assertEqual(md5, lfc.md5)
         self.assertEqual(sha1, lfc.sha1)
         self.assertEqual(sha256, lfc.sha256)
diff --git a/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst b/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst
index a9acb7b..753568a 100644
--- a/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst
+++ b/lib/lp/soyuz/browser/tests/distroseriesqueue-views.rst
@@ -7,10 +7,11 @@ for IDistroSeries context (IDistroSeriesView)
 Let's instantiate the view for +queue for anonymous access:
 
     >>> from zope.component import queryMultiAdapter
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.services.librarian.model import LibraryFileAlias
     >>> from lp.services.webapp.servers import LaunchpadTestRequest
     >>> from lp.registry.interfaces.distribution import IDistributionSet
-    >>> fake_chroot = LibraryFileAlias.get(1)
+    >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1)
 
     >>> ubuntu = getUtility(IDistributionSet)["ubuntu"]
     >>> breezy_autotest = ubuntu["breezy-autotest"]
diff --git a/lib/lp/soyuz/doc/package-diff.rst b/lib/lp/soyuz/doc/package-diff.rst
index 9591382..ac90cfe 100644
--- a/lib/lp/soyuz/doc/package-diff.rst
+++ b/lib/lp/soyuz/doc/package-diff.rst
@@ -120,9 +120,10 @@ already requests a package diff against the immediate ancestry.
 Before starting let's enable the universe component and add the i386
 chroot in hoary in order to be able to accept the NEW packages.
 
-    >>> from lp.soyuz.model.component import ComponentSelection
+    >>> from lp.services.database.interfaces import IStore
     >>> from lp.services.librarian.model import LibraryFileAlias
     >>> from lp.soyuz.interfaces.component import IComponentSet
+    >>> from lp.soyuz.model.component import ComponentSelection
 
     >>> hoary = ubuntu.getSeries("hoary")
     >>> breezy_autotest = ubuntu.getSeries("breezy-autotest")
@@ -130,7 +131,7 @@ chroot in hoary in order to be able to accept the NEW packages.
     >>> universe = getUtility(IComponentSet)["universe"]
     >>> selection = ComponentSelection(distroseries=hoary, component=universe)
 
-    >>> fake_chroot = LibraryFileAlias.get(1)
+    >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1)
     >>> hoary_i386 = hoary["i386"]
     >>> unused = hoary_i386.addOrUpdateChroot(fake_chroot)
     >>> breezy_autotest_i386 = breezy_autotest["i386"]
diff --git a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
index bb8e464..cc0e36d 100644
--- a/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
+++ b/lib/lp/soyuz/doc/soyuz-set-of-uploads.rst
@@ -76,11 +76,11 @@ for the ubuntutest distribution.
 
     >>> from lp.registry.model.distribution import Distribution
     >>> from lp.services.database.interfaces import IStore
+    >>> from lp.services.librarian.model import LibraryFileAlias
     >>> from lp.soyuz.enums import PackageUploadStatus
     >>> from lp.soyuz.scripts.initialize_distroseries import (
     ...     InitializeDistroSeries,
     ... )
-    >>> from lp.services.librarian.model import LibraryFileAlias
     >>> from lp.testing.factory import LaunchpadObjectFactory
     >>> ubuntu = IStore(Distribution).find(Distribution, name="ubuntu").one()
     >>> breezy_autotest = ubuntu["breezy-autotest"]
@@ -110,7 +110,7 @@ for the ubuntutest distribution.
     INFO:...:Copying permissions from parents.
     INFO:...:Creating DistroSeriesDifferences.
     >>> breezy.changeslist = "breezy-changes@xxxxxxxxxx"
-    >>> fake_chroot = LibraryFileAlias.get(1)
+    >>> fake_chroot = IStore(LibraryFileAlias).get(LibraryFileAlias, 1)
     >>> unused = breezy["i386"].addOrUpdateChroot(fake_chroot)
 
 Add disk content for file inherited from ubuntu/breezy-autotest: