diff mbox series

[kteam-tools] ktl: fix new-package crash: no attribute 'stakeholder'

Message ID 1542133569-8223-1-git-send-email-kamal@canonical.com
State New
Headers show
Series [kteam-tools] ktl: fix new-package crash: no attribute 'stakeholder' | expand

Commit Message

Kamal Mostafa Nov. 13, 2018, 6:26 p.m. UTC
Fix crashes when using create-release-tracker --new-package.

Be more careful to not dereference possible NoneType returns from LP API
(as for brand new packages) when looking for the 'stakeholder' attribute.

  File "/home/kamal/src/ckt/kteam-tools/stable/ktl/workflow.py", in assignee_ex
    cursor = cursor.lookup_source(packagename)
    retval = cursor.stakeholder

  AttributeError: 'NoneType' object has no attribute 'stakeholder'

Signed-off-by: Kamal Mostafa <kamal@canonical.com>
---
 ktl/tracking_bug.py | 2 +-
 ktl/workflow.py     | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

Comments

Andy Whitcroft Nov. 13, 2018, 9:30 p.m. UTC | #1
On Tue, Nov 13, 2018 at 10:26:09AM -0800, Kamal Mostafa wrote:
> Fix crashes when using create-release-tracker --new-package.
> 
> Be more careful to not dereference possible NoneType returns from LP API
> (as for brand new packages) when looking for the 'stakeholder' attribute.
> 
>   File "/home/kamal/src/ckt/kteam-tools/stable/ktl/workflow.py", in assignee_ex
>     cursor = cursor.lookup_source(packagename)
>     retval = cursor.stakeholder
> 
>   AttributeError: 'NoneType' object has no attribute 'stakeholder'
> 
> Signed-off-by: Kamal Mostafa <kamal@canonical.com>
> ---
>  ktl/tracking_bug.py | 2 +-
>  ktl/workflow.py     | 5 +++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
> index efea367..bd26f79 100644
> --- a/ktl/tracking_bug.py
> +++ b/ktl/tracking_bug.py
> @@ -109,7 +109,7 @@ class TrackingBug:
>              if lp_series.name == 'stakeholder-signoff':
>                  cursor = self.kernel_series.lookup_series(codename=targeted_series_name)
>                  cursor = cursor.lookup_source(package)
> -                if cursor.stakeholder is None:
> +                if cursor and cursor.stakeholder is None:

As a general rule you should do comparisons against None using is [not]
None:

		   if cursor is not None and cursor.stakeholder is None:

>                      cdebug('    no stakeholder-signoff', 'yellow')
>                      break
>              if lp_series.name == 'promote-to-release' and not self.isdev:
> diff --git a/ktl/workflow.py b/ktl/workflow.py
> index b71e02f..76f83b0 100644
> --- a/ktl/workflow.py
> +++ b/ktl/workflow.py
> @@ -231,8 +231,9 @@ class Workflow:
>              ks = KernelSeries()
>              cursor = ks.lookup_series(codename=series_codename)
>              cursor = cursor.lookup_source(packagename)
> -            retval = cursor.stakeholder
> -        else:
> +            if cursor:

And here.

> +                retval = cursor.stakeholder
> +        if not retval:
>              retval = self.assignee(packagename, taskname, devel)
>          return retval
>  
> -- 

With those fixed:

Acked-by: Andy Whitcroft <apw@canonical.com>

-apw
Kamal Mostafa Nov. 13, 2018, 9:45 p.m. UTC | #2
Applied, with Andy's suggestions.

 -Kamal

On Tue, Nov 13, 2018 at 10:26:09AM -0800, Kamal Mostafa wrote:
> Fix crashes when using create-release-tracker --new-package.
> 
> Be more careful to not dereference possible NoneType returns from LP API
> (as for brand new packages) when looking for the 'stakeholder' attribute.
> 
>   File "/home/kamal/src/ckt/kteam-tools/stable/ktl/workflow.py", in assignee_ex
>     cursor = cursor.lookup_source(packagename)
>     retval = cursor.stakeholder
> 
>   AttributeError: 'NoneType' object has no attribute 'stakeholder'
> 
> Signed-off-by: Kamal Mostafa <kamal@canonical.com>
> ---
>  ktl/tracking_bug.py | 2 +-
>  ktl/workflow.py     | 5 +++--
>  2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
> index efea367..bd26f79 100644
> --- a/ktl/tracking_bug.py
> +++ b/ktl/tracking_bug.py
> @@ -109,7 +109,7 @@ class TrackingBug:
>              if lp_series.name == 'stakeholder-signoff':
>                  cursor = self.kernel_series.lookup_series(codename=targeted_series_name)
>                  cursor = cursor.lookup_source(package)
> -                if cursor.stakeholder is None:
> +                if cursor and cursor.stakeholder is None:
>                      cdebug('    no stakeholder-signoff', 'yellow')
>                      break
>              if lp_series.name == 'promote-to-release' and not self.isdev:
> diff --git a/ktl/workflow.py b/ktl/workflow.py
> index b71e02f..76f83b0 100644
> --- a/ktl/workflow.py
> +++ b/ktl/workflow.py
> @@ -231,8 +231,9 @@ class Workflow:
>              ks = KernelSeries()
>              cursor = ks.lookup_series(codename=series_codename)
>              cursor = cursor.lookup_source(packagename)
> -            retval = cursor.stakeholder
> -        else:
> +            if cursor:
> +                retval = cursor.stakeholder
> +        if not retval:
>              retval = self.assignee(packagename, taskname, devel)
>          return retval
>  
> -- 
> 2.7.4
>
diff mbox series

Patch

diff --git a/ktl/tracking_bug.py b/ktl/tracking_bug.py
index efea367..bd26f79 100644
--- a/ktl/tracking_bug.py
+++ b/ktl/tracking_bug.py
@@ -109,7 +109,7 @@  class TrackingBug:
             if lp_series.name == 'stakeholder-signoff':
                 cursor = self.kernel_series.lookup_series(codename=targeted_series_name)
                 cursor = cursor.lookup_source(package)
-                if cursor.stakeholder is None:
+                if cursor and cursor.stakeholder is None:
                     cdebug('    no stakeholder-signoff', 'yellow')
                     break
             if lp_series.name == 'promote-to-release' and not self.isdev:
diff --git a/ktl/workflow.py b/ktl/workflow.py
index b71e02f..76f83b0 100644
--- a/ktl/workflow.py
+++ b/ktl/workflow.py
@@ -231,8 +231,9 @@  class Workflow:
             ks = KernelSeries()
             cursor = ks.lookup_series(codename=series_codename)
             cursor = cursor.lookup_source(packagename)
-            retval = cursor.stakeholder
-        else:
+            if cursor:
+                retval = cursor.stakeholder
+        if not retval:
             retval = self.assignee(packagename, taskname, devel)
         return retval