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

[Fix] backend_args should not be modified by get_file_backend #897

Merged
merged 1 commit into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions mmengine/fileio/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def _get_file_backend(prefix: str, backend_args: dict):
"""
# backend name has a higher priority
if 'backend' in backend_args:
backend_name = backend_args.pop('backend')
backend = backends[backend_name](**backend_args)
# backend_args should not be modified
backend_args_bak = backend_args.copy()
backend_name = backend_args_bak.pop('backend')
backend = backends[backend_name](**backend_args_bak)
else:
backend = prefix_to_backends[prefix](**backend_args)
return backend
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fileio/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,13 @@ def test_get_file_backend():
backend_args = {'backend': 'local'}
backend = fileio.get_file_backend(uri=None, backend_args=backend_args)
assert isinstance(backend, fileio.backends.LocalBackend)
# backend_args should not be modified
assert backend_args == {'backend': 'local'}

backend_args = {'backend': 'petrel', 'enable_mc': True}
backend = fileio.get_file_backend(uri=None, backend_args=backend_args)
assert isinstance(backend, fileio.backends.PetrelBackend)
assert backend_args == {'backend': 'petrel', 'enable_mc': True}

# backend name has a higher priority
backend_args = {'backend': 'http'}
Expand Down