Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError when parsing configuration file with "yes" option #767

Closed
RenFraser opened this issue Jul 1, 2024 · 7 comments
Closed

AttributeError when parsing configuration file with "yes" option #767

RenFraser opened this issue Jul 1, 2024 · 7 comments
Labels
bug Something isn't working fixed

Comments

@RenFraser
Copy link
Contributor

Issue

When attempting to start aider version v0.41.0, an AttributeError is raised if the .aider.conf.yml configuration file in the user's home directory contains a boolean value (e.g., true or false) or a string representation of a boolean value (e.g., 'true' or 'false'). The error occurs because the configargparse library is trying to call the strip() method on a boolean or string object, which is not supported.

Steps to Reproduce:

  1. Create or modify the .aider.conf.yml file in the user's home directory.
  2. Add any of the following content to the file:
    yes: true
    
    or
    yes: false
    
    or
    yes: 'true'
    
    or
    yes: 'false'
    
  3. Invoke aider by running the command aider in the terminal.

Expected Behavior:
Aider should start up normally without any errors, regardless of whether the configuration file contains boolean values or string representations of boolean values.

Actual Behavior:
An AttributeError is raised with the following stack trace:

~ via ⬢ v20.5.1 
➜ aider -V
Traceback (most recent call last):
  File "/opt/homebrew/bin/aider", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aider/main.py", line 285, in main
    args, unknown = parser.parse_known_args(argv)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/configargparse.py", line 938, in parse_known_args
    [self.get_command_line_key_for_unknown_config_file_setting(key)],
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/configargparse.py", line 1047, in get_command_line_key_for_unknown_config_file_setting
    key_without_prefix_chars = key.strip(self.prefix_chars)
                               ^^^^^^^^^
AttributeError: 'bool' object has no attribute 'strip'

The error occurs regardless of whether the value is true, false, 'true', or 'false'.

Version and model info

Aider version: v0.41.0
Python version: 3.11
Operating System: macOS

@paul-gauthier
Copy link
Collaborator

Thanks for trying aider and filing this issue.

Per the configargparse docs it looks like booleans should be set like:

https://github.com/bw2/ConfigArgParse

# how to set a flag arg (eg. arg which has action="store_true")
--name
name
name = True    # "True" and "true" are the same

I will update the sample .aider.conf.yml file docs.

@paul-gauthier paul-gauthier added the question Further information is requested label Jul 1, 2024
paul-gauthier added a commit that referenced this issue Jul 1, 2024
@paul-gauthier
Copy link
Collaborator

Sorry, this looks like it indeed a bug. Configargparse docs claim that YAMLConfigFileParser format files should accept yes: true. But if you specify config_file_parser_class=configargparse.YAMLConfigFileParser it throws the error you report.

Removing the config_file_parser_class=configargparse.YAMLConfigFileParser it parses yes: true correctly. That seems to use the more flexible DefaultConfigFileParser.

The change is available in the main branch. You can get it by installing the latest version from github:

python -m pip install --upgrade git+https://github.com/paul-gauthier/aider.git

If you have a chance to try it, let me know if it works better for you.

@paul-gauthier paul-gauthier added bug Something isn't working fixed and removed question Further information is requested labels Jul 1, 2024
@RenFraser
Copy link
Contributor Author

Thanks! Tested locally, looks good on my end.

Tested:

  • Startup works with the config for string 'true' and 'false'
  • Startup works with the config for string true and false
  • Writing commits with aider to a local git repo works as expected.

.aider.conf.yml for reference:

dark-mode: true
dirty-commits: false
attribute-author: false
attribute-committer: false
auto-lint: false
lint: false
yes: true

@paul-gauthier
Copy link
Collaborator

I'm going to close this issue for now, but feel free to add a comment here and I will re-open or file a new issue any time.

@paul-gauthier
Copy link
Collaborator

Just went down a rabbit hole to find out why configargparse wouldn't parse a proper yaml config file. Yaml treats yes: whatever as the boolean key True with value whatever. And aider has a --yes parameter, so putting yes: true in your yaml causes a bug when True: True bubbles up from the yaml parser.

Solutions aren't great:

  1. Force everyone to quote the yes arg in their yaml: "yes": true. Possibly scan all yaml for yes: and warn the user to fix it.
  2. Change --yes to --always-yes.

@paul-gauthier paul-gauthier reopened this Oct 2, 2024
@paul-gauthier
Copy link
Collaborator

Relevant: yaml/pyyaml#376

I renamed --yes to --yes-always.

@paul-gauthier
Copy link
Collaborator

Now aider can read proper yaml files, including bulleted lists:

foo:
  - bar
  - baz
  - fob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants