Non-deterministic template order

Bug #490209 reported by Craig Leres
6
This bug affects 1 person
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(path_prefix + '.*'); glob() is
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.

                Craig

Changed in webpy:
assignee: nobody → Anand Chitipothu (anandology)
milestone: none → 0.34
status: New → Confirmed
Revision history for this message
Anand Chitipothu (anandology) wrote :
Changed in webpy:
status: Confirmed → Fix Committed
Changed in webpy:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.