On 07/24/2014 12:35 PM, Tomas Babej wrote:
> Hi,
>
> on receiving a PublicError we fail with InternalError since msg is not
> defined.
>
>
>
> _______________________________________________
> Freeipa-devel mailing list
> Freeipa-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/freeipa-devel

I also realized there's no need for the nested try-blocks, so added some
refactoring to the fix, which makes the code much more simple.



-- 
Tomas Babej
Associate Software Engineer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org 

>From 426e1be07982088b0cc71f705f91d20ad95feef3 Mon Sep 17 00:00:00 2001
From: Tomas Babej <tba...@redhat.com>
Date: Thu, 24 Jul 2014 12:33:35 +0200
Subject: [PATCH] baseldap: Fix undefined variable reference in
 LDAPAddReverseMember and LDAPRemoveReverseMember

---
 ipalib/plugins/baseldap.py | 44 ++++++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 26 deletions(-)

diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 610b9b0f11660996a874fe6151e202f8241c5f27..5367b487e96f5d6d0daf00e72341c50ed5dfface 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -2096,19 +2096,15 @@ class LDAPAddReverseMember(LDAPModReverseMember):
         for attr in options.get(self.reverse_attr) or []:
             try:
                 options = {'%s' % self.member_attr: keys[-1]}
-                try:
-                    result = self._exc_wrapper(keys, options, self.api.Command[self.member_command])(attr, **options)
-                    if result['completed'] == 1:
-                        completed = completed + 1
-                    else:
-                        failed['member'][self.reverse_attr].append((attr, result['failed']['member'][self.member_attr][0][1]))
-                except errors.NotFound, e:
-                    msg = str(e)
-                    (attr, msg) = msg.split(':', 1)
-                    failed['member'][self.reverse_attr].append((attr, unicode(msg.strip())))
-
-            except errors.PublicError, e:
-                failed['member'][self.reverse_attr].append((attr, unicode(msg)))
+                result = self._exc_wrapper(keys, options, self.api.Command[self.member_command])(attr, **options)
+                if result['completed'] == 1:
+                    completed = completed + 1
+                else:
+                    failed['member'][self.reverse_attr].append((attr, result['failed']['member'][self.member_attr][0][1]))
+            except (errors.PublicError, errors.NotFound) as e:
+                msg = str(e)
+                (attr, msg) = msg.split(':', 1)
+                failed['member'][self.reverse_attr].append((attr, unicode(msg.strip())))
 
         # Update the member data.
         entry_attrs = ldap.get_entry(dn, ['*'])
@@ -2197,19 +2193,15 @@ class LDAPRemoveReverseMember(LDAPModReverseMember):
         for attr in options.get(self.reverse_attr) or []:
             try:
                 options = {'%s' % self.member_attr: keys[-1]}
-                try:
-                    result = self._exc_wrapper(keys, options, self.api.Command[self.member_command])(attr, **options)
-                    if result['completed'] == 1:
-                        completed = completed + 1
-                    else:
-                        failed['member'][self.reverse_attr].append((attr, result['failed']['member'][self.member_attr][0][1]))
-                except errors.NotFound, e:
-                    msg = str(e)
-                    (attr, msg) = msg.split(':', 1)
-                    failed['member'][self.reverse_attr].append((attr, unicode(msg.strip())))
-
-            except errors.PublicError, e:
-                failed['member'][self.reverse_attr].append((attr, unicode(msg)))
+                result = self._exc_wrapper(keys, options, self.api.Command[self.member_command])(attr, **options)
+                if result['completed'] == 1:
+                    completed = completed + 1
+                else:
+                    failed['member'][self.reverse_attr].append((attr, result['failed']['member'][self.member_attr][0][1]))
+            except (errors.PublicError, errors.NotFound) as e:
+                msg = str(e)
+                (attr, msg) = msg.split(':', 1)
+                failed['member'][self.reverse_attr].append((attr, unicode(msg.strip())))
 
         # Update the member data.
         entry_attrs = ldap.get_entry(dn, ['*'])
-- 
1.9.3

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to