Tries to read included configs twice

Bug #979905 reported by Michael Nelson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
configglue
Confirmed
Undecided
Unassigned

Bug Description

STR:

1. Create a local.cfg:
{{{
[__main__]
includes = config/foo.cfg
}}}

2. and an arbitrary config/foo.cfg:
{{{
[django]
debug = true
}}}

3. parse the config

ER: should be parsed without warnings
AR: parser parses config/foo.cfg correctly but then tries to parse config/config/foo.cfg with output:

WARNING:root:File /home/michael/ca/sca/current_work/django_project/config/config/foo.cfg could not be read. Skipping.

The reason is that in configglue.parser.SchemaConfigParser._read(), it:
 1) Reads local.cfg with the correct basedir, then checks if the config has an includes option (self.has_option('__main__', 'includes'), and correctly decides it does, so it
 2) Sets self._basedir to point (in this case) to django_project correctly,
 3) Calls self.read() with config/foo.cfg which calls _read() recursively,
 4) It reads config/foo.cfg correctly, and then checks if the config has an includes option, and *incorrectly* decides that it does (as self is really the configparser for local.cfg), so it
 5) updates self._basedir to point to django_project/config (basedir of config/foo.cfg) and tries to read 'config/foo.cfg'.

Without looking deeply, it *looks* like a SchemaConfigParser (which inherits from SafeConfigParser) is meant to represent a single config file (in step 4, self.has_option('__main__', 'includes') is returning true because self is really for local.cfg). Perhaps instead of inheriting from SafeConfigParser, SchemaConfigParser should be a composition of a bunch of SafeConfigParsers - one for each config read?

Changed in configglue:
status: New → Confirmed
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.