Route generation when url_for args=None

4 views
Skip to first unread message

TJ Ninneman

unread,
Jun 4, 2009, 3:45:05 PM6/4/09
to pylons...@googlegroups.com
I've noticed in Routes 1.10.3 that when url_for is called with
arguments which are None, it goes ahead and puts the string 'None' in
the generated URL.

I needed this to change to avoid urls like:

/shop/?source=34465&filters=&product=77987245

or

/shop/?source=34465&filters=None&product=77987245

I went ahead and created a small patch file which checks if the var is
None and if so, doesn't include it in the resultant URL. Hope it
helps if anybody needs it.

http://www.pylonshq.com/pasties/9f17ba4998e211114343428f189286bc

TJ



Mike Orr

unread,
Jun 4, 2009, 5:49:06 PM6/4/09
to pylons...@googlegroups.com

url_for() is complicated so I'm not sure what it should do in all
cases. Certainly it should never covert None to "None". 'filters='
is a valid empty value so there's nothing wrong with that, if we
assume that None should be taken as '', which I'm not sure about. In
any case, we're trying to move users from url_for to pylons.url, which
is better implemented.

I have made my own proposal for a url.current_with_query() which would
reproduce the current URL with query, overriding query params via
keyword args, and deleting any param whose keyword arg is None. That
would be consistent with your proposal.

However, it makes sense to delete query params whose values are None.
It does not make sense to accept None as an override to a path
variable. Neither replacing it with None nor deleting it is
appropriate. Instead, Routes should either raise an error or consider
the route a non-match to the arguments; I'm not sure which is better.

--
Mike Orr <slugg...@gmail.com>

Reply all
Reply to author
Forward
0 new messages