Edgewall Software

Ticket #6551 (new defect)

Opened 13 months ago

Last modified 6 months ago

IntOption and BoolOption values saved even when not differing from default

Reported by: hyuga <hyugaricdeau@…> Owned by: osimons
Priority: low Milestone: 0.11-retriage
Component: general Version: 0.11b1
Severity: minor Keywords:
Cc:

Description

The Configuration.save method fails at checking whether IntOptions and BoolOptions differ from their default values. So when calling Configuration.save, if a value has been set on an IntOption or BoolOption, that value is saved to the file even if it is the same as the default for that option, which is not the desired behavior I don't think.

Attachments

section_get_unicode-r7592.patch (1.0 KB) - added by ebray 3 months ago.
I'm not entirely sure how I feel about this patch, but it does fix the problem as described. Ensures that Section.get() always returns a unicode string, and currectly returns true/false for BoolOptions? and returns an integer string for IntOptions? (even if the value is 0).
section_get_unicode-r7596.patch (1.2 KB) - added by ebray 3 months ago.
A new version of the patch. I found that if an option's default value is None, then Option.__get__ would return u'None' which is certainly no good. I'm still not sure I like this fix, but it gets the job done, and always returns the correct value now.

Change History

Changed 12 months ago by hyuga <hyugaricdeau@…>

It looks like the actual problem here is that Section.get and by extension Configuration.get don't always return a string as documented.

The problem is that if the option is not in the trac.ini file, or the global trac.ini file, its default value is retrieved from the Option registry. In the case of an IntOption, for example, the default value will be an integer. The problem is in how the value is returned. From Section.get:

        if not value:
            return u''
        elif isinstance(value, basestring):
            return to_unicode(value)
        else:
            return value

This leads to all kinds of inconsistencies. For example, if the default value for the option is 0, this returns u'' instead of u'0' as one would expect. Or if the default value is 100000 it will return 100000 as an int.

It should probably be something more like this:

        if value is None:
            return u''
        else:
            return to_unicode(value)

Changed 12 months ago by hyuga <hyugaricdeau@…>

I also noticed that there is some inconsistency with the default values from BoolOptions. For most of them, the defaults are set to 'true' or 'false' as it would appear in the file. But color_scale's default in versioncontrol.web_ui.browser is True., so with my suggested fix this would be returned as u'True', which is still not good.

Changed 11 months ago by hyuga <hyugaricdeau@…>

  • milestone set to 0.11.1

Suggesting a milestone for this since it seems to have gotten lost in the pile.

Changed 6 months ago by osimons

  • owner changed from jonas to osimons

I'll put it on my to-do.

Changed 3 months ago by ebray

I'm not entirely sure how I feel about this patch, but it does fix the problem as described. Ensures that Section.get() always returns a unicode string, and currectly returns true/false for BoolOptions? and returns an integer string for IntOptions? (even if the value is 0).

Changed 3 months ago by ebray

A new version of the patch. I found that if an option's default value is None, then Option.__get__ would return u'None' which is certainly no good. I'm still not sure I like this fix, but it gets the job done, and always returns the correct value now.

Add/Change #6551 (IntOption and BoolOption values saved even when not differing from default)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from osimons. Next status will be 'new'
The owner will change from osimons to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.