[Zope-CMF] SVN: Products.GenericSetup/trunk/Products/GenericSetup/components.py In Zope 2.10 OFS.ObjectManager does not have a get method

Tres Seaver tseaver at palladion.com
Thu Sep 17 22:13:31 EDT 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Laurence Rowe wrote:
> Log message for revision 104254:
>   In Zope 2.10 OFS.ObjectManager does not have a get method
> 
> Changed:
>   U   Products.GenericSetup/trunk/Products/GenericSetup/components.py
> 
> -=-
> Modified: Products.GenericSetup/trunk/Products/GenericSetup/components.py
> ===================================================================
> --- Products.GenericSetup/trunk/Products/GenericSetup/components.py	2009-09-17 17:32:06 UTC (rev 104253)
> +++ Products.GenericSetup/trunk/Products/GenericSetup/components.py	2009-09-17 17:51:28 UTC (rev 104254)
> @@ -221,7 +221,10 @@
>                  if ofs_id not in self.context.objectIds():
>                      self.context._setObject(ofs_id, aq_base(obj),
>                          set_owner=False, suppress_events=True)
> -                obj = self.context.get(ofs_id)
> +                try:
> +                    obj = self.context.get(ofs_id)
> +                except AttributeError:
> +                    obj = self.context[ofs_id] # Zope 2.10
>                  obj.__name__ = ofs_id
>                  obj.__parent__ = aq_base(self.context)
>                  self.context.registerUtility(aq_base(obj), provided, name)

I'm pretty sure the motivation is sound (the GS trunk is still supposed
to support 2.10) but I think __getitem__'s semantics don't match here
(it can raise KeyError, which get doesn't).  Catching AttributeError
also masks the possibility that __getitem__ would be present, but would
raise AttributeError when called.

Maybe instead:

   getter = getattr(self.context, 'get', None)
   if getter is None:
      getter = self.context._getOb # BBB: Zope <= 2.10.x
   obj = getter(ofs_id, None)


Tres.
- --
===================================================================
Tres Seaver          +1 540-429-0999          tseaver at palladion.com
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFKsuzL+gerLs4ltQ4RAnWWAKC4euqQqnsPFsbG0Zi12JUCtygSJQCfS+54
zQJwUiLO0hLEzEB7vs1mx60=
=yHyA
-----END PGP SIGNATURE-----



More information about the Zope-CMF mailing list