#2430: Widgets should use lazy params initialization to prevent from
inconsistence
------------------------+---------------------------------------------------
Reporter: xaka | Owner: chrisz
Type: defect | Status: new
Priority: normal | Milestone: 1.1.x bugfix
Component: TG Widgets | Version: 1.0.9
Severity: normal | Resolution:
Keywords: |
------------------------+---------------------------------------------------
Old description:
> Now, when we pass params to widget's contructor, logic 1st look at
> **params and if nothing was found - check self object. Bah! All params
> stores as ParamDescriptor instances on meta-level and when contructor
> checking self object for param existence it call __get__ of descriptor
> which do getattr(self, param) and call returned value if it callable.
> Where is problem?
>
> {{{
> class MyWidget(turbogears.widgets.Widget):
> @property
> def some_param(self):
> # connect to database, retrieve remote resource
> # or do another operation which can't be processed
> # at __init__ call-time
> ...
> }}}
>
> 1. ParamDescriptor should return None if param is undefined in object
>
> 2. Widget's contructor should not to check self object for param
>
> I've attach patch which fix that logic in right way (IMHO).
New description:
Currently, when you pass params to a widget's constructor, the logic first
looks at `**params` and then, if nothing was found, checks the `self`
object.
All params are stored as `ParamDescriptor` instances on the meta-level and
when the constructor checks the `self` object for param existence it calls
`__get__` of the descriptor, which do `getattr(self, param)` and call the
returned value if it is callable.
Where is the problem?
{{{
class MyWidget(turbogears.widgets.Widget):
@property
def some_param(self):
# connect to database, retrieve remote resource
# or do another operation which can't be processed
# at __init__ call-time
...
}}}
1. `ParamDescriptor` should return `None` if `param` is undefined in
object.
2. The Widget constructor should not check `self` for `param`.
I've attach patch which fix that logic in right way (IMHO).
--
Ticket URL: <http://trac.turbogears.org/ticket/2430#comment:9>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en