Skip to content

bumpversion raises TypeError when repo has no tags #222

@andy-maier

Description

@andy-maier

When there is no bumpversion configuration available anywhere, bumpversion attempts to get the current version from the tags on the local clone of the git repo.

If the local clone has no tags defined, bumpversion fails with TypeError:

$ bumpversion --new-version 24.8.26-a224.dev1 patch --no-tag --no-commit --allow-dirty --verbose
Debug: main: vcs_info={}
Debug: main: defaults={}
Could not read config file at .bumpversion.cfg
Debug: main: after phase 2: known_args.current_version=None
Debug: main: current_version=None
New version will be '24.8.26-a224.dev1'
Asserting files  contain the version string...
new_version=24.8.26-a224.dev1
Would write to config file .bumpversion.cfg:
[bumpversion]
current_version = 24.8.26-a224.dev1


Debug: _commit_to_vcs: current_version=None
Would prepare Git commit
Traceback (most recent call last):
  File "/Users/maiera/virtualenvs/clat38/bin/bumpversion", line 8, in <module>
    sys.exit(main())
  File "/Users/maiera/virtualenvs/clat38/lib/python3.8/site-packages/bumpversion/cli.py", line 139, in main
    context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs,
  File "/Users/maiera/virtualenvs/clat38/lib/python3.8/site-packages/bumpversion/cli.py", line 698, in _commit_to_vcs
    context.update({'current_' + part: current_version[part].value for part in current_version})
TypeError: 'NoneType' object is not iterable

The above is with Python 3.8 in a repo where I deleted all git tags locally, and where there is no bumpversion configuration.

The output above shows a few debug prints that make it clear that in that case, there are no defaults ("Debug: main: defaults={}"), so current_version=None is passed to _commit_to_vcs() which tries to iterate over current_version without checking.

While this may sound like a corner condition, it is actually a real error that happened in one of our pipelines. The pipeline invokes bumpversion, but the project in question moved on to pyproject.toml with setuptools-scm as the versioning support. It would be good if bumpversion would tolerate this condition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions