Skip to content

Commit

Permalink
Avoid __init__ method calls to overridden method
Browse files Browse the repository at this point in the history
Within GitLab plugin there was a call to `iid` method within `Issue`
constructor. That method was overridden by subclasses violating the
invariant that superclasses must be fully initialized before becoming
visible to subclasses.

Signed-off-by: Sandro Bonazzola <[email protected]>
  • Loading branch information
sandrobonazzola committed Mar 4, 2025
1 parent a813f9b commit f415ddf
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions did/plugins/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,14 @@ def search(self, user, since, until, *, target_type, action_name):
class Issue():
""" GitLab Issue """

def __init__(self, data, parent):
def __init__(self, data, parent, set_id=True):
self.parent = parent
self.data = data
self.gitlabapi = parent.gitlab
self.gitlabapi: GitLab = parent.gitlab
self.project = self.gitlabapi.get_project(data['project_id'])
self.id = self.iid()
self.id = None
if set_id:
self.id = self.iid()
self.title = data['target_title']

def iid(self):
Expand Down Expand Up @@ -254,15 +256,25 @@ def __str__(self):
class MergeRequest(Issue):
# pylint: disable=too-few-public-methods

def iid(self):
def __init__(self, data, parent, set_id=True):
super().__init__(data, parent, False)
if set_id:
self.id = self.mr_iid()

def mr_iid(self):
return self.gitlabapi.get_project_mr(
self.data['project_id'], self.data['target_id'])['iid']


class Note(Issue):
# pylint: disable=too-few-public-methods

def iid(self):
def __init__(self, data, parent, set_id=True):
super().__init__(data, parent, False)
if set_id:
self.id = self.note_iid()

def note_iid(self):
if self.data['note']['noteable_type'] == 'Issue':
issue = self.gitlabapi.get_project_issue(
self.data['project_id'],
Expand Down

0 comments on commit f415ddf

Please sign in to comment.