Config parse_if_needed() does not handle removing items with multiple processes
|Reported by:||Owned by:||Jonas Borgström|
I run Apache/mod_python, and multiple processes will therefore access, parse and update the environment config settings. For all 'normal' trac.ini settings this works fine - a change for project description, header logo or anything else where an option (or default) already exists. As expected - so far, so good.
I am writing an Admin plugin for creating, updating and deleting ticket custom fields. It works by adding the various config settings, config.save() and then as each process checks the file timestamp it will (hopefully) do a config.parse_if_needed() and reload settings so that each environment gets the new set of custom fields with correct information.
- Creating works fine. The new options are read and added.
- Updating works fine. Changing type of existing field, changing sort order, updating default values or options for select.
- But; Deleting does not work well as it leads to totally random behaviour when reloading my admin page list of custom fields - it all depends on what process displays the page at a given time as they are out of sync.
Research led me to how the config is actually parsed - and especially when it is re-parsed through
config.parse_if_needed(). This parser depends on each option having some sort of default value in that it is always able to update a field, but has no way of detecting an existing field in current config that should be completely removed - and no trace remaining. Options in 'ticket-custom' section in an environment configuration can only be removed (or reset) by actually restarting server.
So, I have prepared a patch (config-reparse-with-section-delete.diff). With the ongoing work of the new workflow that also is very dependent on trac.ini files for its behavior, I am sure this is of interest to more config sections than my immediate interest. The patch will completely clear out specific sections before parsing the updated file - ensuring that the current settings as defined in trac.ini will be used.