L3_NAT_dbonly_mixin __new__ method has wrong signature

Bug #1657412 reported by Wim De Clercq
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Wishlist
Brian Haley

Bug Description

Since stable/newton, there is this code: https://github.com/openstack/neutron/blob/stable/newton/neutron/db/l3_db.py#L173
master link: https://github.com/openstack/neutron/blob/master/neutron/db/l3_db.py#L95

Python doc says: https://docs.python.org/2/reference/datamodel.html#object.__new__
"...that takes the class of which an instance was requested as its first argument. The remaining arguments are those passed to the object constructor expression..."

Because the __new__ method is overridden in L3_NAT_dbonly_mixin without accepting extra arguments. This forces all subclasses to have either no arguments to the __init__ method, or they have to override __new__ themselves to workaround this.

The following code fails to run:
  from neutron.db import l3_db

  class Test(l3_db.L3_NAT_dbonly_mixin):

      def __init__(self, arg1):
          super(Test, self).__init__()
          self.arg1 = arg1

  Test(1)

--TypeError: __new__() takes exactly 1 argument (2 given)

The, hacky imo, workaround:
  from neutron.db import l3_db

  class Test(l3_db.L3_NAT_dbonly_mixin):

      @staticmethod
      def __new__(cls, *args, **kwargs):
          return super(Test, cls).__new__(cls)

      def __init__(self, arg1):
          super(Test, self).__init__()
          self.arg1 = arg1

  Test(1)

description: updated
description: updated
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.openstack.org/422088

Changed in neutron:
assignee: nobody → aditya_reddy.nagaram@nuagenetworks.net (adityarn)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Fix proposed to branch: master
Review: https://review.openstack.org/422145

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Change abandoned on neutron (master)

Change abandoned by Aditya Reddy Nagaram (<email address hidden>) on branch: master
Review: https://review.openstack.org/422145

Changed in neutron:
importance: Undecided → Wishlist
Changed in neutron:
assignee: aditya_reddy.nagaram@nuagenetworks.net (adityarn) → Kevin Benton (kevinbenton)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

Change abandoned by Armando Migliaccio (<email address hidden>) on branch: master
Review: https://review.openstack.org/422088
Reason: This review is > 4 weeks without comment, and failed Jenkins the last time it was checked. We are abandoning this for now. Feel free to reactivate the review by pressing the restore button and leaving a 'recheck' comment to get fresh test results.

Changed in neutron:
assignee: Kevin Benton (kevinbenton) → Brian Haley (brian-haley)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/422088
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=e862d280681bebecc590ce8853048287cb8d046a
Submitter: Zuul
Branch: master

commit e862d280681bebecc590ce8853048287cb8d046a
Author: Aditya Reddy Nagaram <email address hidden>
Date: Thu Jan 19 15:40:09 2017 +0100

    Allow __new__ method to accept extra arguments

    L3_NAT_dbonly_mixin accepts no extra arguments, but
    some subclasses do want to be able to accept them.

    Change-Id: I069215c4f3031661b7ce2c692dcf4cce1bd29b6c
    Closes-bug: #1657412

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 12.0.0.0b3

This issue was fixed in the openstack/neutron 12.0.0.0b3 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.