#1221 Make _get_module consistent across resolvers
Merged 5 years ago by mprahl. Opened 5 years ago by mprahl.

@@ -40,14 +40,18 @@ 

      def __init__(self, config):

          self.config = config

  

-     def _get_module(self, name, stream, version, context, strict=False):

+     def _get_module(

+         self, name, stream, version, context, state=models.BUILD_STATES['ready'], strict=False,

+     ):

          with models.make_session(self.config) as session:

              mb = models.ModuleBuild.get_build_from_nsvc(

-                 session, name, stream, version, context)

-             if mb is None and strict:

+                 session, name, stream, version, context, state=state)

+             if mb:

+                 return mb.extended_json()

+ 

+             if strict:

                  raise UnprocessableEntity(

                      'Cannot find any module builds for %s:%s' % (name, stream))

-             return mb.extended_json()

  

      def get_module_modulemds(self, name, stream, version=None, context=None, strict=False,

                               stream_version_lte=False):
@@ -68,6 +72,8 @@ 

          """

          if version and context:

              mmd = self._get_module(name, stream, version, context, strict=strict)

+             if mmd is None:

+                 return

              return [self.extract_modulemd(mmd['modulemd'])]

  

          with models.make_session(self.config) as session:

@@ -122,7 +122,9 @@ 

              return modules

  

      def _get_module(self, name, stream, version, context, state="ready", strict=False):

-         return self._get_modules(name, stream, version, context, state, strict)[0]

+         rv = self._get_modules(name, stream, version, context, state, strict)

+         if rv:

+             return rv[0]

  

      def get_module_modulemds(self, name, stream, version=None, context=None, strict=False,

                               stream_version_lte=False):

This also adds additional code in the event a module is not returned so that exceptions aren't unexpectedly raised.

I would rather change conditions so there's no need in such nested code and the code itself would be more compact:
if mb:
return ...
if strict:
raise ...

In my opinion, it doesn't really matter, but I can change it.

rebased onto 1f1f09c249a104ca3d5ce846d24ba1899f3383a5

5 years ago

Okay, the comment was addressed. Thanks for the suggestion @vmaljulin.

rebased onto 3a7786c

5 years ago

Pull-Request has been merged by mprahl

5 years ago