Non-deterministic template order
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
web.py |
Fix Released
|
Undecided
|
Anand Chitipothu |
Bug Description
There's a problem with the way template files are picked. I use a
convention of naming backup or old copies of files with a trailing
minus. I found that in some cases, "index.html-" was being preferred
over "index.html".
The documentation says:
looks for the files matching hello.* in the template root and picks
the first matching file.
It would be a good idea to document what that order is (probably
lexical).
This is implemented using glob.glob(
implemented with os.listdir() which is defined to return a list "in
arbitrary order."
Some quick examples using the -f (unsorted) flag with ls on a FreeBSD
box:
# unsorted
hot 53 % ls -lf | grep html
-rw-r--r-- 1 leres wheel 0 Sep 8 15:49 x.html
-rw-r--r-- 1 leres wheel 0 Sep 8 15:49 i.html
-rw-r--r-- 1 leres wheel 0 Sep 8 15:49 i.html-
hot 54 % rm x.html i.html-
hot 55 % touch i.html-
hot 56 % touch x.html
# unsorted
hot 57 % ls -lf | grep html
-rw-r--r-- 1 leres wheel 0 Sep 8 15:50 x.html
-rw-r--r-- 1 leres wheel 0 Sep 8 15:50 i.html-
-rw-r--r-- 1 leres wheel 0 Sep 8 15:49 i.html
Indeed the unsorted order is arbitrary!
BTW, when you fix this, you might consider removing the check for
backup files:
if not f.endswith('~')] # skip backup files
since they'll sort after all other printable characters.
Changed in webpy: | |
assignee: | nobody → Anand Chitipothu (anandology) |
milestone: | none → 0.34 |
status: | New → Confirmed |
Changed in webpy: | |
status: | Fix Committed → Fix Released |
Fixed.
http:// github. com/webpy/ webpy/commit/ 3d2e2b1