[Grok-dev] Re: SVN: grok/trunk/src/grok/components.py refactor dirty traversal hack

Philipp von Weitershausen philipp at weitershausen.de
Sat May 3 17:58:38 EDT 2008


Hey,

this apparently dirty hack has no tests and due to its unique nature of 
supporting integer container names (which are explicitly not supported 
by Zope itself, and therefore neither in Grok), also has no place in 
Grok. This is definitely something for megrok.rdb or so.

I could find all kinds of specific problems with the actual 
implementation of this hack which would all warrant a test, but having 
established that Grok isn't really the right place, I'd rather not go 
into this :)

I've reverted this with Martijn's consent.

Philipp


P.S.: I would like to re-iterate that we allow no

* feature addition
* bugfix
* change in behaviour

without appropriate test coverage.



Jasper Spaans wrote:
> Log message for revision 86301:
>   refactor dirty traversal hack
> 
> Changed:
>   U   grok/trunk/src/grok/components.py
> 
> -=-
> Modified: grok/trunk/src/grok/components.py
> ===================================================================
> --- grok/trunk/src/grok/components.py	2008-05-03 21:12:15 UTC (rev 86300)
> +++ grok/trunk/src/grok/components.py	2008-05-03 21:22:39 UTC (rev 86301)
> @@ -482,10 +482,15 @@
>              result = traverse(name)
>              if result is not None:
>                  return result
> -        # try to get the item from the container
> -        return self.context.get(name)
> +        # try to get the item from the container, casting it to an int
> +        # if the key might be an int (which is quite reasonable for a
> +        # key that lives in a database)
> +        # XXX this is a dirty hack, but it works fine
> +        try:
> +            return self.context.get(type(self.context.keys()[0])(name))
> +        except KeyError:
> +            return self.context.get(name)
>  
> -
>  default_form_template = PageTemplateFile(os.path.join(
>      'templates', 'default_edit_form.pt'))
>  default_form_template.__grok_name__ = 'default_edit_form'



More information about the Grok-dev mailing list