[PATCH] fix for bug 12293, was fix for bug 12292

Rowland Penny repenny241155 at gmail.com
Wed Sep 28 18:32:59 UTC 2016


On Wed, 28 Sep 2016 21:14:39 +0300
Alexander Bokovoy <ab at samba.org> wrote:

> On ke, 28 syys 2016, Rowland Penny wrote:
> > On Wed, 28 Sep 2016 17:37:37 +0300
> > Alexander Bokovoy <ab at samba.org> wrote:
> > 
> > > On ke, 28 syys 2016, Rowland Penny wrote:
> > > > > > > However, I think Douglas was trying to point out that it
> > > > > > > is bad practice in Python programming to have 'except'
> > > > > > > without specific exception -- catch-all cases are almost
> > > > > > > every time wrong. So if you know that there will be an
> > > > > > > index error, just catch that exception type to handle it
> > > > > > > properly.
> > > > > > 
> > > > > > Well yes, but I only found out what the exception was by
> > > > > > adding 'Exception, e' to the line i.e. I hadn't a clue
> > > > > > 
> > > > > > I personally think you are all getting bogged down in
> > > > > > technicalities here, what does it matter why the user
> > > > > > couldn't be found, it couldn't be found!
> > > > > Correct. However, if there would be another reason, like
> > > > > genuine error in the underlying software stack, the 'except
> > > > > IndexError, e' exception handling would allow us to crash
> > > > > with a proper backtrace to see that issue. A plain 'except:'
> > > > > or 'except Exception, e' will cover up any error and will
> > > > > complicate debugging. That's one point why we insist on this
> > > > > technicality.
> > > > > 
> > > > 
> > > > OK, that's me over there waving the white flag ;-)
> > > > 
> > > > I will alter the patch to use 'except IndexError, e' ,
> > > > but before I do, is there anything else wrong with my patch ???
> > > I don't see anything else being incorrect in it.
> > > 
> > 
> > OK, See the attached patch
> > 
> > Rowland
> >  
> 
> > From a502ea005820b80e857e7d02af4e772895bcfef5 Mon Sep 17 00:00:00
> > 2001 From: Rowland Penny <rpenny at samba.org>
> > Date: Wed, 28 Sep 2016 15:39:52 +0100
> > Subject: [PATCH] bug 12292: stop user.py throwing errors if user is
> > unknown
> > 
> > Signed-off-by: Rowland Penny <rpenny at samba.org>
> > ---
> >  python/samba/netcmd/user.py | 19 ++++++++++++++++---
> >  1 file changed, 16 insertions(+), 3 deletions(-)
> > 
> > diff --git a/python/samba/netcmd/user.py
> > b/python/samba/netcmd/user.py index 5adc287..10f98f4 100644
> > --- a/python/samba/netcmd/user.py
> > +++ b/python/samba/netcmd/user.py
> > @@ -406,10 +406,23 @@ Example2 shows how to delete a user in the
> > domain against the local server.   su lp = sambaopts.get_loadparm()
> >          creds = credopts.get_credentials(lp, fallback_machine=True)
> >  
> > +        samdb = SamDB(url=H, session_info=system_session(),
> > +                      credentials=creds, lp=lp)
> > +
> > +        filter =
> > ("(&(sAMAccountName=%s)(sAMAccountType=805306368))" %
> > +                   username)
> > +
> >          try:
> > -            samdb = SamDB(url=H, session_info=system_session(),
> > -                          credentials=creds, lp=lp)
> > -            samdb.deleteuser(username)
> > +            res = samdb.search(base=samdb.domain_dn(),
> > +                               scope=ldb.SCOPE_SUBTREE,
> > +                               expression=filter,
> > +                               attrs=["dn"])
> > +            user_dn = res[0].dn
> > +        except IndexError, e:
> > +            raise CommandError('Unable to find user "%s"' %
> > (username), e) +
> > +        try:
> > +            samdb.delete(user_dn)
> >          except Exception, e:
> >              raise CommandError('Failed to remove user "%s"' %
> > username, e) self.outf.write("Deleted user %s\n" % username)
> > -- 
> > 2.1.4
> > 
> 
> Thanks. Looks good to me. RB+. Can you add another one for the group
> case as you promised and then I'll push them.
> 

Patch attached.

Rowland

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bug-12293-stop-group.py-throwing-errors-if-group-is-.patch
Type: text/x-patch
Size: 1735 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160928/483d6d3d/bug-12293-stop-group.py-throwing-errors-if-group-is-.bin>


More information about the samba-technical mailing list