launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30466
[Merge] ~cjwatson/launchpad:remove-sqlobjectnotfound into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:remove-sqlobjectnotfound into launchpad:master.
Commit message:
Remove all remaining uses of SQLObjectNotFound
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/451657
This includes fixes for test failures caused by "Convert LibraryFile{Alias,Content} queries to Storm" and "Convert Archive to Storm".
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:remove-sqlobjectnotfound into launchpad:master.
diff --git a/lib/lp/archiveuploader/uploadprocessor.py b/lib/lp/archiveuploader/uploadprocessor.py
index f7cd1ae..9093bdc 100644
--- a/lib/lp/archiveuploader/uploadprocessor.py
+++ b/lib/lp/archiveuploader/uploadprocessor.py
@@ -77,7 +77,6 @@ from lp.code.interfaces.sourcepackagerecipebuild import (
from lp.oci.interfaces.ocirecipebuild import IOCIRecipeBuild
from lp.registry.interfaces.distribution import IDistributionSet
from lp.registry.interfaces.person import IPersonSet
-from lp.services.database.sqlobject import SQLObjectNotFound
from lp.services.log.logger import BufferLogger
from lp.services.statsd.interfaces.statsd_client import IStatsdClient
from lp.services.webapp.adapter import (
@@ -1020,9 +1019,8 @@ def parse_upload_path(relative_path):
elif first_path.isdigit():
# This must be a binary upload from a build worker.
- try:
- archive = getUtility(IArchiveSet).get(int(first_path))
- except SQLObjectNotFound:
+ archive = getUtility(IArchiveSet).get(int(first_path))
+ if archive is None:
raise UploadPathError(
"Could not find archive with id=%s." % first_path
)
diff --git a/lib/lp/code/mail/tests/test_codehandler.py b/lib/lp/code/mail/tests/test_codehandler.py
index 82d770d..eeb65e1 100644
--- a/lib/lp/code/mail/tests/test_codehandler.py
+++ b/lib/lp/code/mail/tests/test_codehandler.py
@@ -149,7 +149,7 @@ class TestCodeHandler(TestCaseWithFactory):
self.code_handler.process(mail, email_addr, None),
"Succeeded, but didn't return True",
)
- # if the message has not been created, this raises SQLObjectNotFound
+ # if the message has not been created, this raises NotFoundError.
MessageSet().get("<my-id>")
def test_process_packagebranch(self):
diff --git a/lib/lp/registry/model/sharingjob.py b/lib/lp/registry/model/sharingjob.py
index bf2bb78..3bb50f1 100644
--- a/lib/lp/registry/model/sharingjob.py
+++ b/lib/lp/registry/model/sharingjob.py
@@ -20,6 +20,7 @@ from zope.component import getUtility
from zope.interface import implementer, provider
from lp.app.enums import InformationType
+from lp.app.errors import NotFoundError
from lp.blueprints.interfaces.specification import ISpecification
from lp.blueprints.model.specification import Specification
from lp.blueprints.model.specificationsearch import (
@@ -61,7 +62,6 @@ from lp.registry.model.teammembership import TeamParticipation
from lp.services.config import config
from lp.services.database.enumcol import DBEnum
from lp.services.database.interfaces import IStore
-from lp.services.database.sqlobject import SQLObjectNotFound
from lp.services.database.stormbase import StormBase
from lp.services.job.model.job import EnumeratedSubclass, Job
from lp.services.job.runner import BaseRunnableJob
@@ -193,12 +193,12 @@ class SharingJobDerived(BaseRunnableJob, metaclass=EnumeratedSubclass):
:return: the SharingJob with the specified id, as the
current SharingJobDereived subclass.
- :raises: SQLObjectNotFound if there is no job with the specified id,
+ :raises: NotFoundError if there is no job with the specified id,
or its job_type does not match the desired subclass.
"""
job = SharingJob.get(job_id)
if job.job_type != cls.class_job_type:
- raise SQLObjectNotFound(
+ raise NotFoundError(
"No object found with id %d and type %s"
% (job_id, cls.class_job_type.title)
)
diff --git a/lib/lp/services/authserver/tests/test_authserver.py b/lib/lp/services/authserver/tests/test_authserver.py
index 2f29fd1..3961957 100644
--- a/lib/lp/services/authserver/tests/test_authserver.py
+++ b/lib/lp/services/authserver/tests/test_authserver.py
@@ -6,12 +6,12 @@
import xmlrpc.client
from pymacaroons import Macaroon
-from storm.sqlobject import SQLObjectNotFound
from testtools.matchers import Equals, Is, MatchesListwise, MatchesStructure
from zope.component import getUtility
from zope.interface import implementer
from zope.publisher.xmlrpc import TestRequest
+from lp.app.errors import NotFoundError
from lp.services.authserver.interfaces import (
IAuthServer,
IAuthServerApplication,
@@ -266,7 +266,7 @@ class MacaroonTests(TestCaseWithFactory):
# Pick a large ID that doesn't exist in sampledata.
lfa_id = 1000000
self.assertRaises(
- SQLObjectNotFound,
+ NotFoundError,
getUtility(ILibraryFileAliasSet).__getitem__,
lfa_id,
)
diff --git a/lib/lp/services/authserver/xmlrpc.py b/lib/lp/services/authserver/xmlrpc.py
index 54312d7..74758fe 100644
--- a/lib/lp/services/authserver/xmlrpc.py
+++ b/lib/lp/services/authserver/xmlrpc.py
@@ -9,12 +9,12 @@ __all__ = [
]
from pymacaroons import Macaroon
-from storm.sqlobject import SQLObjectNotFound
from zope.component import getUtility
from zope.interface import implementer
from zope.interface.interfaces import ComponentLookupError
from zope.security.proxy import removeSecurityProxy
+from lp.app.errors import NotFoundError
from lp.code.interfaces.cibuild import ICIBuildSet
from lp.oci.interfaces.ocirecipebuild import IOCIRecipeBuildSet
from lp.registry.interfaces.person import IPersonSet
@@ -69,7 +69,7 @@ class AuthServerAPIView(LaunchpadXMLRPCView):
# The context is a `LibraryFileAlias` ID.
try:
return getUtility(ILibraryFileAliasSet)[context]
- except SQLObjectNotFound:
+ except NotFoundError:
return None
elif context_type == "BinaryPackageBuild":
# The context is a `BinaryPackageBuild` ID.
diff --git a/lib/lp/services/database/sqlobject/__init__.py b/lib/lp/services/database/sqlobject/__init__.py
index 4013d35..13fabdc 100644
--- a/lib/lp/services/database/sqlobject/__init__.py
+++ b/lib/lp/services/database/sqlobject/__init__.py
@@ -26,7 +26,6 @@ from storm.sqlobject import ( # noqa: F401
SQLMultipleJoin,
SQLObjectBase,
SQLObjectMoreThanOneResultError,
- SQLObjectNotFound,
SQLObjectResultSet,
SQLRelatedJoin,
StringCol,
diff --git a/lib/lp/snappy/browser/snapbase.py b/lib/lp/snappy/browser/snapbase.py
index 719bb26..30facc8 100644
--- a/lib/lp/snappy/browser/snapbase.py
+++ b/lib/lp/snappy/browser/snapbase.py
@@ -10,7 +10,6 @@ __all__ = [
from zope.component import getUtility
-from lp.services.database.sqlobject import SQLObjectNotFound
from lp.services.webapp import GetitemNavigation, Navigation, stepthrough
from lp.snappy.interfaces.snapbase import ISnapBase, ISnapBaseSet
from lp.soyuz.interfaces.archive import IArchiveSet
@@ -35,9 +34,8 @@ class SnapBaseNavigation(Navigation):
# Not a number.
return None
- try:
- archive = getUtility(IArchiveSet).get(id)
- except SQLObjectNotFound:
+ archive = getUtility(IArchiveSet).get(id)
+ if archive is None:
return None
return self.context.getArchiveDependency(archive)
diff --git a/lib/lp/soyuz/browser/archive.py b/lib/lp/soyuz/browser/archive.py
index f46da5b..61186a3 100644
--- a/lib/lp/soyuz/browser/archive.py
+++ b/lib/lp/soyuz/browser/archive.py
@@ -75,7 +75,6 @@ from lp.services.browser_helpers import (
get_user_agent_distroseries,
)
from lp.services.database.bulk import load_related
-from lp.services.database.sqlobject import SQLObjectNotFound
from lp.services.helpers import english_list
from lp.services.job.model.job import Job
from lp.services.librarian.browser import (
@@ -433,9 +432,8 @@ class ArchiveNavigation(Navigation, FileNavigationMixin):
# Not a number.
return None
- try:
- archive = getUtility(IArchiveSet).get(id)
- except SQLObjectNotFound:
+ archive = getUtility(IArchiveSet).get(id)
+ if archive is None:
return None
return self.context.getArchiveDependency(archive)
diff --git a/lib/lp/translations/scripts/fix_plural_forms.py b/lib/lp/translations/scripts/fix_plural_forms.py
index 8bdebac..1ad2836 100644
--- a/lib/lp/translations/scripts/fix_plural_forms.py
+++ b/lib/lp/translations/scripts/fix_plural_forms.py
@@ -9,7 +9,6 @@ __all__ = [
from lp.services.database.interfaces import IStore
from lp.services.database.sqlbase import cursor
-from lp.services.database.sqlobject import SQLObjectNotFound
from lp.translations.interfaces.translations import TranslationConstants
from lp.translations.model.pofile import POFile
from lp.translations.model.potmsgset import POTMsgSet
@@ -83,8 +82,6 @@ def fix_plurals_in_all_pofiles(ztm, logger):
cur.execute("""SELECT MAX(id) FROM POFile""")
(max_pofile_id,) = cur.fetchall()[0]
for pofile_id in range(1, max_pofile_id):
- try:
- pofile = IStore(POFile).get(POFile, pofile_id)
+ pofile = IStore(POFile).get(POFile, pofile_id)
+ if pofile is not None:
fix_pofile_plurals(pofile, logger, ztm)
- except SQLObjectNotFound:
- pass