Edgewall Software
Modify

Opened 8 years ago

Closed 7 years ago

#12779 closed defect (fixed)

[logging] log_level option is case-sensitive after Trac 1.2

Reported by: Jun Omae Owned by: Ryan J Ollos
Priority: normal Milestone: 1.2.2
Component: general Version: 1.2
Severity: minor Keywords:
Cc: Branch:
Release Notes:

Fixed [logging] log_level and log_type were incorrectly case-sensitive after Trac 1.1.3.

API Changes:

Added case_sensitive argument to ChoiceOption, which defaults to True for backwards compatibility.

Internal Changes:

Description

$ ~/venv/trac/1.0.13/trac-admin /dev/shm/tracenv-1.0
Welcome to trac-admin 1.0.13
Interactive Trac administration console.
Copyright (C) 2003-2013 Edgewall Software

Type:  '?' or 'help' for help on commands.

Trac [/dev/shm/tracenv-1.0]> config get logging log_level
info
Trac [/dev/shm/tracenv-1.0]>
$ ~/venv/trac/1.2/trac-admin /dev/shm/tracenv-1.0
Welcome to trac-admin 1.2
Interactive Trac administration console.
Copyright (C) 2003-2013 Edgewall Software

Type:  '?' or 'help' for help on commands.

Trac [/dev/shm/tracenv-1.0]> upgrade
Error: [logging] log_level: expected one of ("ALL", "CRITICAL", "DEBUG", "ERROR", "INFO", "WARN", "WARNING"), got u'info'

Attachments (0)

Change History (5)

comment:1 by Ryan J Ollos, 8 years ago

Owner: set to Ryan J Ollos
Release Notes: modified (diff)
Status: newassigned

Regression from #11573. We could add a case_sensitive argument to ChoiceOption.

  • trac/config.py

    diff --git a/trac/config.py b/trac/config.py
    index cd43e8887..b8ad92e0e 100644
    a b class ChoiceOption(Option):  
    819819    """
    820820
    821821    def __init__(self, section, name, choices, doc='', doc_domain='tracini',
    822                  doc_args=None):
     822                 doc_args=None, case_sensitive=True):
    823823        Option.__init__(self, section, name, to_unicode(choices[0]), doc,
    824824                        doc_domain, doc_args)
    825825        self.choices = set(to_unicode(c).strip() for c in choices)
     826        self.case_sensitive = case_sensitive
    826827
    827828    def accessor(self, section, name, default):
    828829        value = section.get(name, default)
    829         if value not in self.choices:
     830        choices = self.choices
     831        if not self.case_sensitive:
     832            value = value.lower()
     833            choices = map(unicode.lower, choices)
     834        if value not in choices:
    830835            raise ConfigurationError(
    831836                    _('[%(section)s] %(entry)s: expected one of '
    832837                      '(%(choices)s), got %(value)s',
  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    index 0ecbb5b42..19c2b5f3d 100644
    a b class Environment(Component, ComponentManager):  
    250250        """Level of verbosity in log.
    251251
    252252        Should be one of (`CRITICAL`, `ERROR`, `WARNING`, `INFO`, `DEBUG`).
    253         """)
     253        """, case_sensitive=False)
    254254
    255255    log_format = Option('logging', 'log_format', None,
    256256        """Custom logging format.

I would prefer to not make case_sensitive be the last argument in the list, but I suppose that is required for backward-compatibility.

comment:2 by Ryan J Ollos, 8 years ago

Alternative patch:

  • trac/config.py

    commit a1cdc51045c544364e40e7ceea31ded4540d30bd
    Author: Ryan J Ollos <ryan.j.ollos@gmail.com>
    Date:   Wed Apr 19 09:40:34 2017 -0700
    
        Allow arbitrary function
    
    diff --git a/trac/config.py b/trac/config.py
    index cd43e8887..0aada371b 100644
    a b class ChoiceOption(Option):  
    819819    """
    820820
    821821    def __init__(self, section, name, choices, doc='', doc_domain='tracini',
    822                  doc_args=None):
     822                 doc_args=None, fn=None):
    823823        Option.__init__(self, section, name, to_unicode(choices[0]), doc,
    824824                        doc_domain, doc_args)
    825825        self.choices = set(to_unicode(c).strip() for c in choices)
     826        self.fn = fn
    826827
    827828    def accessor(self, section, name, default):
    828829        value = section.get(name, default)
     830        if self.fn:
     831            value = self.fn(value)
    829832        if value not in self.choices:
    830833            raise ConfigurationError(
    831834                    _('[%(section)s] %(entry)s: expected one of '
  • trac/env.py

    diff --git a/trac/env.py b/trac/env.py
    index 0ecbb5b42..40b676182 100644
    a b class Environment(Component, ComponentManager):  
    250250        """Level of verbosity in log.
    251251
    252252        Should be one of (`CRITICAL`, `ERROR`, `WARNING`, `INFO`, `DEBUG`).
    253         """)
     253        """, fn=unicode.upper)
    254254
    255255    log_format = Option('logging', 'log_format', None,
    256256        """Custom logging format.

If we go with this patch we probably want to extend the changes to apply to Option and its derivative classes.

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:3 by Ryan J Ollos, 8 years ago

Yet another option would be to subclass ChoiceOption and create a case-insensitive class with otherwise the same behavior, ChoiceOptionI.

comment:4 by Ryan J Ollos, 8 years ago

Milestone: next-stable-1.2.x1.2.2

comment:5 by Ryan J Ollos, 7 years ago

API Changes: modified (diff)
Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

comment:1 change committed to 1.2-stable in r15928, merged to trunk in r15929.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.