URL: https://github.com/freeipa/freeipa/pull/1013
Author: davidkupka
 Title: #1013: schema: Fix internal error in param-{find,show} with nonexistent 
object
Action: opened

PR body:
"""

"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1013/head:pr1013
git checkout pr1013
From 986b15d057e520d3e4fedb3c20fde8831ea6ee49 Mon Sep 17 00:00:00 2001
From: David Kupka <dku...@redhat.com>
Date: Tue, 29 Aug 2017 16:49:36 +0200
Subject: [PATCH] schema: Fix internal error in param-{find,show} with
 nonexistent object

---
 ipaserver/plugins/schema.py | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/ipaserver/plugins/schema.py b/ipaserver/plugins/schema.py
index 1dbbec5f03..2ed669ded1 100644
--- a/ipaserver/plugins/schema.py
+++ b/ipaserver/plugins/schema.py
@@ -624,16 +624,25 @@ def _get_obj(self, metaobj_param, **kwargs):
         return obj
 
     def _retrieve(self, metaobjectfull_name, name, **kwargs):
+        found = False
         try:
             metaobj = self.api.Command[metaobjectfull_name]
             plugin = self.api.Object['command']
         except KeyError:
-            metaobj = self.api.Object[metaobjectfull_name]
-            plugin = self.api.Object['class']
+            try:
+                metaobj = self.api.Object[metaobjectfull_name]
+                plugin = self.api.Object['class']
+            except KeyError:
+                pass
+            else:
+                found = True
+        else:
+            found = True
 
-        for param in plugin._iter_params(metaobj):
-            if param.name == name:
-                return metaobj, param
+        if found:
+            for param in plugin._iter_params(metaobj):
+                if param.name == name:
+                    return metaobj, param
 
         raise errors.NotFound(
             reason=_("%(pkey)s: %(oname)s not found") % {
@@ -646,8 +655,11 @@ def _search(self, metaobjectfull_name, **kwargs):
             metaobj = self.api.Command[metaobjectfull_name]
             plugin = self.api.Object['command']
         except KeyError:
-            metaobj = self.api.Object[metaobjectfull_name]
-            plugin = self.api.Object['class']
+            try:
+                metaobj = self.api.Object[metaobjectfull_name]
+                plugin = self.api.Object['class']
+            except KeyError:
+                return tuple()
 
         return ((metaobj, param) for param in plugin._iter_params(metaobj))
 
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to