You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by Apache Bloodhound <de...@bloodhound.apache.org> on 2013/06/30 05:43:50 UTC

[Apache Bloodhound] #579: ProductizedHref fails for dicts as first arg

#579: ProductizedHref fails for dicts as first arg
---------------------+---------------
  Reporter:  olemis  |    Owner:
      Type:  defect  |   Status:  new
  Priority:  major   |  Version:
Resolution:          |
---------------------+---------------
 Productized Href breaks Href contract when dict objects are passed as
 first argument.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  olemis
      Type:  defect        |     Status:  accepted
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by olemis):

 * status:  new => accepted
 * owner:  nobody => olemis


Old description:

> Productized Href breaks Href contract when dict objects are passed as
> first argument. See sample code below
>
> {{{!#py
>
> >>> from trac.web.href import Href
> >>> h = Href('/x/y')
> >>> p = dict(a=1,b=2,c=3)
> >>> h(p)
> '/x/y?a=1&c=3&b=2'
> >>> from multiproduct.hooks import ProductizedHref
> >>> help(ProductizedHref)
>
> >>> help(ProductizedHref)
>
> >>> phref = ProductizedHref(h, 'z')
> >>> phref(p)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "multiproduct/hooks.py", line 106, in __call__
>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>   File "multiproduct/hooks.py", line 106, in <lambda>
>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> AttributeError: 'dict' object has no attribute 'startswith'
> }}}

New description:

 Productized Href breaks Href contract when dict objects are passed as
 first argument. See sample code below

 {{{#!py

 >>> from trac.web.href import Href
 >>> h = Href('/x/y')
 >>> p = dict(a=1,b=2,c=3)
 >>> h(p)
 '/x/y?a=1&c=3&b=2'
 >>> from multiproduct.hooks import ProductizedHref
 >>> help(ProductizedHref)

 >>> help(ProductizedHref)

 >>> phref = ProductizedHref(h, 'z')
 >>> phref(p)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "multiproduct/hooks.py", line 106, in __call__
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
   File "multiproduct/hooks.py", line 106, in <lambda>
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
 AttributeError: 'dict' object has no attribute 'startswith'
 }}}

--

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:2>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  rjollos
      Type:  defect        |     Status:  review
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by rjollos):

 * owner:  gjm => rjollos


Comment:

 (In [1503938])

 Added additional unit tests for `ProductizedHref`. Refs #579.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:8>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  olemis
      Type:  defect        |     Status:  accepted
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------

Comment (by olemis):

 Attached patch will fix this issue . Details :

 {{{#!sh

 $ hg qapplied
 t579/t579_r1497837_mp_href_dict.diff

 $ hg log -r qparent --template="[{svnrev}] - {desc}\n"
 [1496958] - More robust handling of resources in timeline widget.

 Should fix problem described in #547.
 }}}

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:3>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Ryan Ollos <ry...@wandisco.com>.
On Tue, Jul 16, 2013 at 12:19 PM, Jure Zitnik <ju...@digiverse.si> wrote:

> On 7/16/13 8:46 PM, Ryan Ollos wrote:
>
>> On Tue, Jul 16, 2013 at 11:38 AM, Matevž Bradač <ma...@digiverse.si>
>> wrote:
>>
>>  On 16. Jul, 2013, at 18:58, Ryan Ollos wrote:
>>>
>>>  On Mon, Jul 15, 2013 at 3:18 PM, Apache Bloodhound <
>>>> dev@bloodhound.apache.org> wrote:
>>>>
>>>>  #579: ProductizedHref fails for dicts as first argument
>>>>> ---------------------------+--**---------------------
>>>>>   Reporter:  olemis        |      Owner:  gjm
>>>>>       Type:  defect        |     Status:  review
>>>>>   Priority:  major         |  Milestone:  Release 7
>>>>> Component:  multiproduct  |    Version:
>>>>> Resolution:                |   Keywords:  web href
>>>>> ---------------------------+--**---------------------
>>>>> Changes (by olemis):
>>>>>
>>>>> * owner:  olemis => gjm
>>>>>
>>>>>
>>>>> Old description:
>>>>>
>>>>>  Productized Href breaks Href contract when dict objects are passed as
>>>>>> first argument. See sample code below
>>>>>>
>>>>>> {{{#!py
>>>>>>
>>>>>>  from trac.web.href import Href
>>>>>>>>> h = Href('/x/y')
>>>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>>>> h(p)
>>>>>>>>>
>>>>>>>> '/x/y?a=1&c=3&b=2'
>>>>>>
>>>>>>>  from multiproduct.hooks import ProductizedHref
>>>>>>>>> help(ProductizedHref)
>>>>>>>>> help(ProductizedHref)
>>>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>>>> phref(p)
>>>>>>>>>
>>>>>>>> Traceback (most recent call last):
>>>>>>   File "<stdin>", line 1, in <module>
>>>>>>   File "multiproduct/hooks.py", line 106, in __call__
>>>>>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>>>   File "multiproduct/hooks.py", line 106, in <lambda>
>>>>>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>>> AttributeError: 'dict' object has no attribute 'startswith'
>>>>>> }}}
>>>>>>
>>>>> New description:
>>>>>
>>>>> Productized Href breaks Href contract when dict objects are passed as
>>>>> first argument. See sample code below
>>>>>
>>>>> {{{#!py
>>>>>
>>>>>  from trac.web.href import Href
>>>>>>>> h = Href('/x/y')
>>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>>> h(p)
>>>>>>>>
>>>>>>> '/x/y?a=1&c=3&b=2'
>>>>>
>>>>>>  from multiproduct.hooks import ProductizedHref
>>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>>> phref(p)
>>>>>>>>
>>>>>>> Traceback (most recent call last):
>>>>>    File "<stdin>", line 1, in <module>
>>>>>    File "multiproduct/hooks.py", line 106, in __call__
>>>>>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>>    File "multiproduct/hooks.py", line 106, in <lambda>
>>>>>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>> AttributeError: 'dict' object has no attribute 'startswith'
>>>>> }}}
>>>>>
>>>>> --
>>>>>
>>>>> Comment:
>>>>>
>>>>> This is what I get now
>>>>>
>>>>> {{{#!py
>>>>>
>>>>>  from trac.web.href import Href
>>>>>>>> h = Href('/x/y')
>>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>>> h(p)
>>>>>>>>
>>>>>>> '/x/y?a=1&c=3&b=2'
>>>>>
>>>>>>  from multiproduct.hooks import ProductizedHref
>>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>>> phref(p)
>>>>>>>>
>>>>>>> 'z?a=1&c=3&b=2'
>>>>> }}}
>>>>>
>>>>> Looks much better, but now that I take a look I'm not sure either of
>>>>> whether that's the expected behavior. I just tried to fix the error and
>>>>> stay a bit out of the way wrt semantics. I really only use
>>>>> `ProductizedHref` in my local testing environment; never in production
>>>>> (that I recall), so I guess **now** I'm not the right person to comment
>>>>>
>>>> on
>>>
>>>> this subject, beyond my comments above. I'm forwarding this review
>>>>>
>>>> request
>>>
>>>> to gjm . He might have a few ideas.
>>>>>
>>>>>   From SVN annotate, I see that Jure committed the code we have
>>>> questions
>>>> about in r1453351. Jure, could you help us understand the intended
>>>>
>>> behavior
>>>
>>>> of ProductizedHref?
>>>>
>>> IIRC the ProductizedHref is a wrapper for Href to help with creation of
>>> product-scoped URLs from any environment, be it a global, or another
>>> product.
>>> It's mainly used in the global dashboard's product widgets, so that hrefs
>>> to
>>> product specific milestones, versions etc. are readily available.
>>> (The other use in ProductRequestWithFactory seems obsolete, except in
>>> tests)
>>>
>>> Looking at recent fixes from Olemis (#552), it seems that ProductizedHref
>>> may
>>> not be needed anymore and could be removed (from tests as well)?
>>>
>>
>> Ah, thanks. I hadn't looked to see that ProductRequestWithSession isn't
>> used anywhere either. I will look at removing both ProductizedHref and
>> ProductRequestWithSession after #552 is applied.
>>
>>  The ProductizedHref is, as Matevz already mentioned, a wrapper that
> encapsulates global Href and renders either product scoped or global (for
> PATHS_NO_TRANSFORM, STATIC_PREFIXES) URLs. Creation of ProductizedHref is
> controlled by ProductRequestWithSession.
>
> Example would be:
> > from trac.web.href import Href
> > from multiproduct.hooks import ProductizedHref
> > global_href = Href('/')
> > product_href = ProductizedHref(global_href, '/myproduct')
> > product_href.admin(a=2, b=3)
> '/admin?a=2&b=3'
> > product_href.milestone(a=2, b=3)
> '/myproduct/milestone?a=2&b=3'
>
> The use of ProductizedHref should be completely transparent as it's hidden
> from the code through the ProductRequestFactory ...
>
> Cheers,
> Jure



Okay, now I see how this is set and used through the `[trac]
request_factory` configuration setting.

I was mainly confused by an example such as the following
> global_href = Href('/base')
> product_href = ProductizedHref(global_href, '/myproduct')
> product_href.admin(a=2, b=3)
'/base/admin?a=2&b=3'
> product_href.milestone(a=2, b=3)
'/myproduct/milestone?a=2&b=3'

I expected the `ProductizedHref` to prepend the global href base so that
the last string would be '/base/myproduct/milestone?a=2&b=3'

By debugging through the code I see now that in practice the following
values would be passed:
> global_href = Href('/base')
> product_href = ProductizedHref(global_href, '/base/myproduct')

(i.e. the product base would *not* be relative to the global base) which
leads to the result:
> product_href.milestone(a=2, b=3)
'/base/myproduct/milestone?a=2&b=3'

I will add some unit tests and close out #579.

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Matevž Bradač <ma...@digiverse.si>.
On 16. Jul, 2013, at 21:36, Olemis Lang wrote:

> On 7/16/13, Jure Zitnik <ju...@digiverse.si> wrote:
> [...]
>> 
>> The ProductizedHref is, as Matevz already mentioned, a wrapper that
>> encapsulates global Href and renders either product scoped or global
>> (for PATHS_NO_TRANSFORM, STATIC_PREFIXES) URLs. Creation of
>> ProductizedHref is controlled by ProductRequestWithSession.
>> 
>> Example would be:
>>> from trac.web.href import Href
>>> from multiproduct.hooks import ProductizedHref
>>> global_href = Href('/')
>>> product_href = ProductizedHref(global_href, '/myproduct')
>>> product_href.admin(a=2, b=3)
>> '/admin?a=2&b=3'
>>> product_href.milestone(a=2, b=3)
>> '/myproduct/milestone?a=2&b=3'
>> 
>> The use of ProductizedHref should be completely transparent as it's
>> hidden from the code through the ProductRequestFactory ...
>> 
> 
> So , putting this answer in context considering the original question
> posed by Ryan in the ticket it seems to me that the answer is that
> sample code in comment::ticket:579 works as expected because base URL
> is provided as second arg .
> 
> Anyway previous messages made me  recall Branko's message (citation
> needed) regarding the decision of using default product config for
> upgrades and deprecating its use for anything else. JFTR ,
> 
> I've been deploying 0.6 without using ProductizedHref . Instead I
> supply RequestWithSession ... but beware of the fact that it MUST be
> patched to insert _global_href attribute because it seems to be used
> in Genshi templates and leads to a number of serious failures .
> 
> Should we have a separate ticket for applying such changes and related
> enhancements ?

That makes sense to me. Perhaps a smallish BEP could also be considered,
to document the current state/findings and solutions?

> 
> -- 
> Regards,
> 
> Olemis.


Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Olemis Lang <ol...@gmail.com>.
On 7/16/13, Jure Zitnik <ju...@digiverse.si> wrote:
[...]
>
> The ProductizedHref is, as Matevz already mentioned, a wrapper that
> encapsulates global Href and renders either product scoped or global
> (for PATHS_NO_TRANSFORM, STATIC_PREFIXES) URLs. Creation of
> ProductizedHref is controlled by ProductRequestWithSession.
>
> Example would be:
>  > from trac.web.href import Href
>  > from multiproduct.hooks import ProductizedHref
>  > global_href = Href('/')
>  > product_href = ProductizedHref(global_href, '/myproduct')
>  > product_href.admin(a=2, b=3)
> '/admin?a=2&b=3'
>  > product_href.milestone(a=2, b=3)
> '/myproduct/milestone?a=2&b=3'
>
> The use of ProductizedHref should be completely transparent as it's
> hidden from the code through the ProductRequestFactory ...
>

So , putting this answer in context considering the original question
posed by Ryan in the ticket it seems to me that the answer is that
sample code in comment::ticket:579 works as expected because base URL
is provided as second arg .

Anyway previous messages made me  recall Branko's message (citation
needed) regarding the decision of using default product config for
upgrades and deprecating its use for anything else. JFTR ,

I've been deploying 0.6 without using ProductizedHref . Instead I
supply RequestWithSession ... but beware of the fact that it MUST be
patched to insert _global_href attribute because it seems to be used
in Genshi templates and leads to a number of serious failures .

Should we have a separate ticket for applying such changes and related
enhancements ?

-- 
Regards,

Olemis.

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Jure Zitnik <ju...@digiverse.si>.
On 7/16/13 8:46 PM, Ryan Ollos wrote:
> On Tue, Jul 16, 2013 at 11:38 AM, Matevž Bradač <ma...@digiverse.si> wrote:
>
>> On 16. Jul, 2013, at 18:58, Ryan Ollos wrote:
>>
>>> On Mon, Jul 15, 2013 at 3:18 PM, Apache Bloodhound <
>>> dev@bloodhound.apache.org> wrote:
>>>
>>>> #579: ProductizedHref fails for dicts as first argument
>>>> ---------------------------+-----------------------
>>>>   Reporter:  olemis        |      Owner:  gjm
>>>>       Type:  defect        |     Status:  review
>>>>   Priority:  major         |  Milestone:  Release 7
>>>> Component:  multiproduct  |    Version:
>>>> Resolution:                |   Keywords:  web href
>>>> ---------------------------+-----------------------
>>>> Changes (by olemis):
>>>>
>>>> * owner:  olemis => gjm
>>>>
>>>>
>>>> Old description:
>>>>
>>>>> Productized Href breaks Href contract when dict objects are passed as
>>>>> first argument. See sample code below
>>>>>
>>>>> {{{#!py
>>>>>
>>>>>>>> from trac.web.href import Href
>>>>>>>> h = Href('/x/y')
>>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>>> h(p)
>>>>> '/x/y?a=1&c=3&b=2'
>>>>>>>> from multiproduct.hooks import ProductizedHref
>>>>>>>> help(ProductizedHref)
>>>>>>>> help(ProductizedHref)
>>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>>> phref(p)
>>>>> Traceback (most recent call last):
>>>>>   File "<stdin>", line 1, in <module>
>>>>>   File "multiproduct/hooks.py", line 106, in __call__
>>>>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>>   File "multiproduct/hooks.py", line 106, in <lambda>
>>>>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>> AttributeError: 'dict' object has no attribute 'startswith'
>>>>> }}}
>>>> New description:
>>>>
>>>> Productized Href breaks Href contract when dict objects are passed as
>>>> first argument. See sample code below
>>>>
>>>> {{{#!py
>>>>
>>>>>>> from trac.web.href import Href
>>>>>>> h = Href('/x/y')
>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>> h(p)
>>>> '/x/y?a=1&c=3&b=2'
>>>>>>> from multiproduct.hooks import ProductizedHref
>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>> phref(p)
>>>> Traceback (most recent call last):
>>>>    File "<stdin>", line 1, in <module>
>>>>    File "multiproduct/hooks.py", line 106, in __call__
>>>>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>>    File "multiproduct/hooks.py", line 106, in <lambda>
>>>>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>> AttributeError: 'dict' object has no attribute 'startswith'
>>>> }}}
>>>>
>>>> --
>>>>
>>>> Comment:
>>>>
>>>> This is what I get now
>>>>
>>>> {{{#!py
>>>>
>>>>>>> from trac.web.href import Href
>>>>>>> h = Href('/x/y')
>>>>>>> p = dict(a=1,b=2,c=3)
>>>>>>> h(p)
>>>> '/x/y?a=1&c=3&b=2'
>>>>>>> from multiproduct.hooks import ProductizedHref
>>>>>>> phref = ProductizedHref(h, 'z')
>>>>>>> phref(p)
>>>> 'z?a=1&c=3&b=2'
>>>> }}}
>>>>
>>>> Looks much better, but now that I take a look I'm not sure either of
>>>> whether that's the expected behavior. I just tried to fix the error and
>>>> stay a bit out of the way wrt semantics. I really only use
>>>> `ProductizedHref` in my local testing environment; never in production
>>>> (that I recall), so I guess **now** I'm not the right person to comment
>> on
>>>> this subject, beyond my comments above. I'm forwarding this review
>> request
>>>> to gjm . He might have a few ideas.
>>>>
>>>  From SVN annotate, I see that Jure committed the code we have questions
>>> about in r1453351. Jure, could you help us understand the intended
>> behavior
>>> of ProductizedHref?
>> IIRC the ProductizedHref is a wrapper for Href to help with creation of
>> product-scoped URLs from any environment, be it a global, or another
>> product.
>> It's mainly used in the global dashboard's product widgets, so that hrefs
>> to
>> product specific milestones, versions etc. are readily available.
>> (The other use in ProductRequestWithFactory seems obsolete, except in
>> tests)
>>
>> Looking at recent fixes from Olemis (#552), it seems that ProductizedHref
>> may
>> not be needed anymore and could be removed (from tests as well)?
>
> Ah, thanks. I hadn't looked to see that ProductRequestWithSession isn't
> used anywhere either. I will look at removing both ProductizedHref and
> ProductRequestWithSession after #552 is applied.
>
The ProductizedHref is, as Matevz already mentioned, a wrapper that 
encapsulates global Href and renders either product scoped or global 
(for PATHS_NO_TRANSFORM, STATIC_PREFIXES) URLs. Creation of 
ProductizedHref is controlled by ProductRequestWithSession.

Example would be:
 > from trac.web.href import Href
 > from multiproduct.hooks import ProductizedHref
 > global_href = Href('/')
 > product_href = ProductizedHref(global_href, '/myproduct')
 > product_href.admin(a=2, b=3)
'/admin?a=2&b=3'
 > product_href.milestone(a=2, b=3)
'/myproduct/milestone?a=2&b=3'

The use of ProductizedHref should be completely transparent as it's 
hidden from the code through the ProductRequestFactory ...

Cheers,
Jure


Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Ryan Ollos <ry...@wandisco.com>.
On Tue, Jul 16, 2013 at 11:38 AM, Matevž Bradač <ma...@digiverse.si> wrote:

>
> On 16. Jul, 2013, at 18:58, Ryan Ollos wrote:
>
> > On Mon, Jul 15, 2013 at 3:18 PM, Apache Bloodhound <
> > dev@bloodhound.apache.org> wrote:
> >
> >> #579: ProductizedHref fails for dicts as first argument
> >> ---------------------------+-----------------------
> >>  Reporter:  olemis        |      Owner:  gjm
> >>      Type:  defect        |     Status:  review
> >>  Priority:  major         |  Milestone:  Release 7
> >> Component:  multiproduct  |    Version:
> >> Resolution:                |   Keywords:  web href
> >> ---------------------------+-----------------------
> >> Changes (by olemis):
> >>
> >> * owner:  olemis => gjm
> >>
> >>
> >> Old description:
> >>
> >>> Productized Href breaks Href contract when dict objects are passed as
> >>> first argument. See sample code below
> >>>
> >>> {{{#!py
> >>>
> >>>>>> from trac.web.href import Href
> >>>>>> h = Href('/x/y')
> >>>>>> p = dict(a=1,b=2,c=3)
> >>>>>> h(p)
> >>> '/x/y?a=1&c=3&b=2'
> >>>>>> from multiproduct.hooks import ProductizedHref
> >>>>>> help(ProductizedHref)
> >>>
> >>>>>> help(ProductizedHref)
> >>>
> >>>>>> phref = ProductizedHref(h, 'z')
> >>>>>> phref(p)
> >>> Traceback (most recent call last):
> >>>  File "<stdin>", line 1, in <module>
> >>>  File "multiproduct/hooks.py", line 106, in __call__
> >>>    filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> >>>  File "multiproduct/hooks.py", line 106, in <lambda>
> >>>    filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> >>> AttributeError: 'dict' object has no attribute 'startswith'
> >>> }}}
> >>
> >> New description:
> >>
> >> Productized Href breaks Href contract when dict objects are passed as
> >> first argument. See sample code below
> >>
> >> {{{#!py
> >>
> >>>>> from trac.web.href import Href
> >>>>> h = Href('/x/y')
> >>>>> p = dict(a=1,b=2,c=3)
> >>>>> h(p)
> >> '/x/y?a=1&c=3&b=2'
> >>>>> from multiproduct.hooks import ProductizedHref
> >>>>> phref = ProductizedHref(h, 'z')
> >>>>> phref(p)
> >> Traceback (most recent call last):
> >>   File "<stdin>", line 1, in <module>
> >>   File "multiproduct/hooks.py", line 106, in __call__
> >>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> >>   File "multiproduct/hooks.py", line 106, in <lambda>
> >>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> >> AttributeError: 'dict' object has no attribute 'startswith'
> >> }}}
> >>
> >> --
> >>
> >> Comment:
> >>
> >> This is what I get now
> >>
> >> {{{#!py
> >>
> >>>>> from trac.web.href import Href
> >>>>> h = Href('/x/y')
> >>>>> p = dict(a=1,b=2,c=3)
> >>>>> h(p)
> >> '/x/y?a=1&c=3&b=2'
> >>>>> from multiproduct.hooks import ProductizedHref
> >>>>> phref = ProductizedHref(h, 'z')
> >>>>> phref(p)
> >> 'z?a=1&c=3&b=2'
> >> }}}
> >>
> >> Looks much better, but now that I take a look I'm not sure either of
> >> whether that's the expected behavior. I just tried to fix the error and
> >> stay a bit out of the way wrt semantics. I really only use
> >> `ProductizedHref` in my local testing environment; never in production
> >> (that I recall), so I guess **now** I'm not the right person to comment
> on
> >> this subject, beyond my comments above. I'm forwarding this review
> request
> >> to gjm . He might have a few ideas.
> >>
> >
> > From SVN annotate, I see that Jure committed the code we have questions
> > about in r1453351. Jure, could you help us understand the intended
> behavior
> > of ProductizedHref?
>
> IIRC the ProductizedHref is a wrapper for Href to help with creation of
> product-scoped URLs from any environment, be it a global, or another
> product.
> It's mainly used in the global dashboard's product widgets, so that hrefs
> to
> product specific milestones, versions etc. are readily available.
> (The other use in ProductRequestWithFactory seems obsolete, except in
> tests)
>
> Looking at recent fixes from Olemis (#552), it seems that ProductizedHref
> may
> not be needed anymore and could be removed (from tests as well)?


Ah, thanks. I hadn't looked to see that ProductRequestWithSession isn't
used anywhere either. I will look at removing both ProductizedHref and
ProductRequestWithSession after #552 is applied.

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Matevž Bradač <ma...@digiverse.si>.
On 16. Jul, 2013, at 18:58, Ryan Ollos wrote:

> On Mon, Jul 15, 2013 at 3:18 PM, Apache Bloodhound <
> dev@bloodhound.apache.org> wrote:
> 
>> #579: ProductizedHref fails for dicts as first argument
>> ---------------------------+-----------------------
>>  Reporter:  olemis        |      Owner:  gjm
>>      Type:  defect        |     Status:  review
>>  Priority:  major         |  Milestone:  Release 7
>> Component:  multiproduct  |    Version:
>> Resolution:                |   Keywords:  web href
>> ---------------------------+-----------------------
>> Changes (by olemis):
>> 
>> * owner:  olemis => gjm
>> 
>> 
>> Old description:
>> 
>>> Productized Href breaks Href contract when dict objects are passed as
>>> first argument. See sample code below
>>> 
>>> {{{#!py
>>> 
>>>>>> from trac.web.href import Href
>>>>>> h = Href('/x/y')
>>>>>> p = dict(a=1,b=2,c=3)
>>>>>> h(p)
>>> '/x/y?a=1&c=3&b=2'
>>>>>> from multiproduct.hooks import ProductizedHref
>>>>>> help(ProductizedHref)
>>> 
>>>>>> help(ProductizedHref)
>>> 
>>>>>> phref = ProductizedHref(h, 'z')
>>>>>> phref(p)
>>> Traceback (most recent call last):
>>>  File "<stdin>", line 1, in <module>
>>>  File "multiproduct/hooks.py", line 106, in __call__
>>>    filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>>  File "multiproduct/hooks.py", line 106, in <lambda>
>>>    filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>> AttributeError: 'dict' object has no attribute 'startswith'
>>> }}}
>> 
>> New description:
>> 
>> Productized Href breaks Href contract when dict objects are passed as
>> first argument. See sample code below
>> 
>> {{{#!py
>> 
>>>>> from trac.web.href import Href
>>>>> h = Href('/x/y')
>>>>> p = dict(a=1,b=2,c=3)
>>>>> h(p)
>> '/x/y?a=1&c=3&b=2'
>>>>> from multiproduct.hooks import ProductizedHref
>>>>> phref = ProductizedHref(h, 'z')
>>>>> phref(p)
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>   File "multiproduct/hooks.py", line 106, in __call__
>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>>   File "multiproduct/hooks.py", line 106, in <lambda>
>>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>> AttributeError: 'dict' object has no attribute 'startswith'
>> }}}
>> 
>> --
>> 
>> Comment:
>> 
>> This is what I get now
>> 
>> {{{#!py
>> 
>>>>> from trac.web.href import Href
>>>>> h = Href('/x/y')
>>>>> p = dict(a=1,b=2,c=3)
>>>>> h(p)
>> '/x/y?a=1&c=3&b=2'
>>>>> from multiproduct.hooks import ProductizedHref
>>>>> phref = ProductizedHref(h, 'z')
>>>>> phref(p)
>> 'z?a=1&c=3&b=2'
>> }}}
>> 
>> Looks much better, but now that I take a look I'm not sure either of
>> whether that's the expected behavior. I just tried to fix the error and
>> stay a bit out of the way wrt semantics. I really only use
>> `ProductizedHref` in my local testing environment; never in production
>> (that I recall), so I guess **now** I'm not the right person to comment on
>> this subject, beyond my comments above. I'm forwarding this review request
>> to gjm . He might have a few ideas.
>> 
> 
> From SVN annotate, I see that Jure committed the code we have questions
> about in r1453351. Jure, could you help us understand the intended behavior
> of ProductizedHref?

IIRC the ProductizedHref is a wrapper for Href to help with creation of
product-scoped URLs from any environment, be it a global, or another product.
It's mainly used in the global dashboard's product widgets, so that hrefs to
product specific milestones, versions etc. are readily available.
(The other use in ProductRequestWithFactory seems obsolete, except in tests)

Looking at recent fixes from Olemis (#552), it seems that ProductizedHref may
not be needed anymore and could be removed (from tests as well)?

--
matevz


Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Ryan Ollos <ry...@wandisco.com>.
On Mon, Jul 15, 2013 at 3:18 PM, Apache Bloodhound <
dev@bloodhound.apache.org> wrote:

> #579: ProductizedHref fails for dicts as first argument
> ---------------------------+-----------------------
>   Reporter:  olemis        |      Owner:  gjm
>       Type:  defect        |     Status:  review
>   Priority:  major         |  Milestone:  Release 7
>  Component:  multiproduct  |    Version:
> Resolution:                |   Keywords:  web href
> ---------------------------+-----------------------
> Changes (by olemis):
>
>  * owner:  olemis => gjm
>
>
> Old description:
>
> > Productized Href breaks Href contract when dict objects are passed as
> > first argument. See sample code below
> >
> > {{{#!py
> >
> > >>> from trac.web.href import Href
> > >>> h = Href('/x/y')
> > >>> p = dict(a=1,b=2,c=3)
> > >>> h(p)
> > '/x/y?a=1&c=3&b=2'
> > >>> from multiproduct.hooks import ProductizedHref
> > >>> help(ProductizedHref)
> >
> > >>> help(ProductizedHref)
> >
> > >>> phref = ProductizedHref(h, 'z')
> > >>> phref(p)
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in <module>
> >   File "multiproduct/hooks.py", line 106, in __call__
> >     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> >   File "multiproduct/hooks.py", line 106, in <lambda>
> >     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> > AttributeError: 'dict' object has no attribute 'startswith'
> > }}}
>
> New description:
>
>  Productized Href breaks Href contract when dict objects are passed as
>  first argument. See sample code below
>
>  {{{#!py
>
>  >>> from trac.web.href import Href
>  >>> h = Href('/x/y')
>  >>> p = dict(a=1,b=2,c=3)
>  >>> h(p)
>  '/x/y?a=1&c=3&b=2'
>  >>> from multiproduct.hooks import ProductizedHref
>  >>> phref = ProductizedHref(h, 'z')
>  >>> phref(p)
>  Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>    File "multiproduct/hooks.py", line 106, in __call__
>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>    File "multiproduct/hooks.py", line 106, in <lambda>
>      filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>  AttributeError: 'dict' object has no attribute 'startswith'
>  }}}
>
> --
>
> Comment:
>
>  This is what I get now
>
>  {{{#!py
>
>  >>> from trac.web.href import Href
>  >>> h = Href('/x/y')
>  >>> p = dict(a=1,b=2,c=3)
>  >>> h(p)
>  '/x/y?a=1&c=3&b=2'
>  >>> from multiproduct.hooks import ProductizedHref
>  >>> phref = ProductizedHref(h, 'z')
>  >>> phref(p)
>  'z?a=1&c=3&b=2'
>  }}}
>
>  Looks much better, but now that I take a look I'm not sure either of
>  whether that's the expected behavior. I just tried to fix the error and
>  stay a bit out of the way wrt semantics. I really only use
>  `ProductizedHref` in my local testing environment; never in production
>  (that I recall), so I guess **now** I'm not the right person to comment on
>  this subject, beyond my comments above. I'm forwarding this review request
>  to gjm . He might have a few ideas.
>

>From SVN annotate, I see that Jure committed the code we have questions
about in r1453351. Jure, could you help us understand the intended behavior
of ProductizedHref?

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  gjm
      Type:  defect        |     Status:  review
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by olemis):

 * owner:  olemis => gjm


Old description:

> Productized Href breaks Href contract when dict objects are passed as
> first argument. See sample code below
>
> {{{#!py
>
> >>> from trac.web.href import Href
> >>> h = Href('/x/y')
> >>> p = dict(a=1,b=2,c=3)
> >>> h(p)
> '/x/y?a=1&c=3&b=2'
> >>> from multiproduct.hooks import ProductizedHref
> >>> help(ProductizedHref)
>
> >>> help(ProductizedHref)
>
> >>> phref = ProductizedHref(h, 'z')
> >>> phref(p)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "multiproduct/hooks.py", line 106, in __call__
>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
>   File "multiproduct/hooks.py", line 106, in <lambda>
>     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
> AttributeError: 'dict' object has no attribute 'startswith'
> }}}

New description:

 Productized Href breaks Href contract when dict objects are passed as
 first argument. See sample code below

 {{{#!py

 >>> from trac.web.href import Href
 >>> h = Href('/x/y')
 >>> p = dict(a=1,b=2,c=3)
 >>> h(p)
 '/x/y?a=1&c=3&b=2'
 >>> from multiproduct.hooks import ProductizedHref
 >>> phref = ProductizedHref(h, 'z')
 >>> phref(p)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "multiproduct/hooks.py", line 106, in __call__
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
   File "multiproduct/hooks.py", line 106, in <lambda>
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
 AttributeError: 'dict' object has no attribute 'startswith'
 }}}

--

Comment:

 This is what I get now

 {{{#!py

 >>> from trac.web.href import Href
 >>> h = Href('/x/y')
 >>> p = dict(a=1,b=2,c=3)
 >>> h(p)
 '/x/y?a=1&c=3&b=2'
 >>> from multiproduct.hooks import ProductizedHref
 >>> phref = ProductizedHref(h, 'z')
 >>> phref(p)
 'z?a=1&c=3&b=2'
 }}}

 Looks much better, but now that I take a look I'm not sure either of
 whether that's the expected behavior. I just tried to fix the error and
 stay a bit out of the way wrt semantics. I really only use
 `ProductizedHref` in my local testing environment; never in production
 (that I recall), so I guess **now** I'm not the right person to comment on
 this subject, beyond my comments above. I'm forwarding this review request
 to gjm . He might have a few ideas.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:7>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:
      Type:  defect        |     Status:  review
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by olemis):

 * owner:  olemis =>
 * status:  accepted => review


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:4>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  rjollos
      Type:  defect        |     Status:  closed
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:  fixed         |   Keywords:  web href
---------------------------+-----------------------
Changes (by rjollos):

 * status:  review => closed
 * resolution:   => fixed


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:9>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  olemis
      Type:  defect        |     Status:  review
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by rjollos):

 * owner:  rjollos => olemis


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:6>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  rjollos
      Type:  defect        |     Status:  review
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by rjollos):

 * owner:   => rjollos


Comment:

 I'm having trouble understanding how `ProductizedHref` should behave, and
 it's only used in two places so I've not had much success inferring the
 behavior. The only places I see it used are:
 {{{
 bloodhound/bloodhound_dashboard/bhdashboard/widgets/product.py:
 href = ProductizedHref(self.env, penv.href.base)
 bloodhound/bloodhound_multiproduct/multiproduct/hooks.py:
 self.href = ProductizedHref(env.parent.href, env.href.base)
 bloodhound/bloodhound_multiproduct/multiproduct/hooks.py:
 self.abs_href = ProductizedHref(env.parent.abs_href,
 }}}

 The use in `product.py` seems incorrect (passing an `Environment` object
 as the first argument rather than an `Href` argument), but it looks like
 you've already fixed that in #552.

 What is the expected output from your test case. I have guessed it should
 be `'/x/y/z?a=1&c=3&b=2`, but that's not what I'm seeing after writing a
 test case.

 You'll see that I've done two things:
  * Added a unit test to test the correct behavior and also document the
 intended behavior.
  * Modified the patch to first check that the first argument is a string
 before performing the other checks that depend on the first argument being
 a string.

 ----

 (In [1503454])

 Added a failing test case for `Href` contract violation. Refs #579.

 (In [1503456])

 Fix for `ProductizedHref` throwing an exception when a dictionary is the
 first argument. Refs #579.

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:5>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument (was: ProductizedHref fails for dicts as first arg)

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------
  Reporter:  olemis        |      Owner:  nobody
      Type:  defect        |     Status:  new
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:                |   Keywords:  web href
---------------------------+-----------------------
Changes (by olemis):

 * component:   => multiproduct
 * keywords:   => web href
 * milestone:   => Release 7
 * owner:   => nobody


Old description:

> Productized Href breaks Href contract when dict objects are passed as
> first argument.

New description:

 Productized Href breaks Href contract when dict objects are passed as
 first argument. See sample code below

 {{{!#py

 >>> from trac.web.href import Href
 >>> h = Href('/x/y')
 >>> p = dict(a=1,b=2,c=3)
 >>> h(p)
 '/x/y?a=1&c=3&b=2'
 >>> from multiproduct.hooks import ProductizedHref
 >>> help(ProductizedHref)

 >>> help(ProductizedHref)

 >>> phref = ProductizedHref(h, 'z')
 >>> phref(p)
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "multiproduct/hooks.py", line 106, in __call__
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
   File "multiproduct/hooks.py", line 106, in <lambda>
     filter(lambda x: args[0].startswith(x), self.STATIC_PREFIXES):
 AttributeError: 'dict' object has no attribute 'startswith'
 }}}

--

-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:1>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker

Re: [Apache Bloodhound] #579: ProductizedHref fails for dicts as first argument

Posted by Apache Bloodhound <de...@bloodhound.apache.org>.
#579: ProductizedHref fails for dicts as first argument
---------------------------+-----------------------------
  Reporter:  olemis        |      Owner:  rjollos
      Type:  defect        |     Status:  closed
  Priority:  major         |  Milestone:  Release 7
 Component:  multiproduct  |    Version:
Resolution:  fixed         |   Keywords:  web href, bhnet
---------------------------+-----------------------------
Changes (by olemis):

 * keywords:  web href => web href, bhnet


-- 
Ticket URL: <https://issues.apache.org/bloodhound/ticket/579#comment:10>
Apache Bloodhound <https://issues.apache.org/bloodhound/>
The Apache Bloodhound issue tracker