← Back to team overview

configglue team mailing list archive

[Bug 979905] [NEW] Tries to read included configs twice

 

Public bug reported:

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?

** Affects: configglue
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of
Configglue developers, which is the registrant for configglue.
https://bugs.launchpad.net/bugs/979905

Title:
  Tries to read included configs twice

Status in configglue:
  New

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?

To manage notifications about this bug go to:
https://bugs.launchpad.net/configglue/+bug/979905/+subscriptions


Follow ups

References