[Toaster] [PATCH 2/4] toaster: prevent exception when Project.release is null
Elliot Smith
elliot.smith at intel.com
Mon Apr 11 04:27:25 PDT 2016
Project.release can be null. This causes an exception when calling
get_all_compatible_layer_versions(), as the query to fetch
the layer versions references release.branch_name.
Add a guard to the function so that an empty queryset is returned
if the release isn't set for a project.
Signed-off-by: Elliot Smith <elliot.smith at intel.com>
---
bitbake/lib/toaster/orm/models.py | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/bitbake/lib/toaster/orm/models.py b/bitbake/lib/toaster/orm/models.py
index 68c3072..f0a8786 100644
--- a/bitbake/lib/toaster/orm/models.py
+++ b/bitbake/lib/toaster/orm/models.py
@@ -264,11 +264,17 @@ class Project(models.Model):
def get_all_compatible_layer_versions(self):
""" Returns Queryset of all Layer_Versions which are compatible with
this project"""
- queryset = Layer_Version.objects.filter(
- (Q(up_branch__name=self.release.branch_name) &
- Q(build=None) &
- Q(project=None)) |
- Q(project=self))
+ queryset = None
+
+ # guard on release, as it can be null
+ if self.release:
+ queryset = Layer_Version.objects.filter(
+ (Q(up_branch__name=self.release.branch_name) &
+ Q(build=None) &
+ Q(project=None)) |
+ Q(project=self))
+ else:
+ queryset = Layer_Version.objects.none()
return queryset
--
1.9.3
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
More information about the toaster
mailing list