#234 Fix python3 issue caused by comparing `None` and `int` compose.koji_event.
Merged 6 months ago by jkaluza. Opened 6 months ago by jkaluza.
jkaluza/odcs none-koji-event  into  master

@@ -439,7 +439,8 @@ 

          # example submitted 1 year ago, so koji_event will be one year old.

          # But the `old_compose` was submitted few days ago at max.

          # In this case, we must never reuse the newer compose for old one.

-         if compose.koji_event < old_compose.koji_event:

+         if (compose.koji_event and old_compose.koji_event and

This will get the job done, but I wonder if a default should be defined for the Compose model. Something like this maybe:

koji_event = db.Column(db.Integer, default=int)

This of course, would likely require cleaning up existing data. Not sure if sqlalchemy will do this update when needed on its own.

+                 compose.koji_event < old_compose.koji_event):

              log.debug("%r: Cannot reuse %r - koji_event of current compose "

                        "is lower than koji_event of old compose.", compose,

                        old_compose)

@@ -250,6 +250,31 @@ 

  

      @patch("odcs.server.backend.koji_get_inherited_tags")

      @patch("odcs.server.backend.create_koji_session")

+     def test_get_reusable_tag_compose_none_koji_event(

+             self, create_koji_session, koji_get_inherited_tags):

+         koji_get_inherited_tags.return_value = ["foo", "bar"]

+         koji_session = MagicMock()

+         create_koji_session.return_value = koji_session

+         koji_session.tagChangedSinceEvent.return_value = False

+ 

+         old_c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         old_c.koji_event = None

+         old_c.state = COMPOSE_STATES["done"]

+         c = Compose.create(

+             db.session, "me", PungiSourceType.KOJI_TAG, "foo",

+             COMPOSE_RESULTS["repository"], 3600, packages="ed")

+         c.koji_event = 2

+         db.session.add(old_c)

+         db.session.add(c)

+         db.session.commit()

+ 

+         reused_c = get_reusable_compose(c)

+         self.assertEqual(reused_c, old_c)

+ 

+     @patch("odcs.server.backend.koji_get_inherited_tags")

+     @patch("odcs.server.backend.create_koji_session")

      def test_get_reusable_tag_compose_tag_changed(

              self, create_koji_session, koji_get_inherited_tags):

          koji_get_inherited_tags.return_value = ["foo", "bar"]

Comparing None and int is not possible in python3, but works in python2.
The compose.koji_event is unset for modular composes, because the modular
Koji tag does not change once the module is built and therefore it is
not needed to track the koji_even on which the compose was generated.

This will get the job done, but I wonder if a default should be defined for the Compose model. Something like this maybe:

koji_event = db.Column(db.Integer, default=int)

This of course, would likely require cleaning up existing data. Not sure if sqlalchemy will do this update when needed on its own.

Pull-Request has been merged by jkaluza

6 months ago