Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Fix to prevent infinite recursion in __getattr__ #646

Closed
wants to merge 1 commit into from

Conversation

yaelbh
Copy link

@yaelbh yaelbh commented May 29, 2023

I'm trying to deep-copy a backend. But then I enter an infinite recursion:

  File "/home/yaelbh/miniconda3/envs/env1/lib/python3.9/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/yaelbh/miniconda3/envs/env1/lib/python3.9/copy.py", line 271, in _reconstruct
    if hasattr(y, '__setstate__'):
  File "/home/yaelbh/miniconda3/envs/env1/lib/python3.9/site-packages/qiskit_ibm_provider/ibm_backend.py", line 247, in __getattr__
    return self._configuration.__getattribute__(name)
  File "/home/yaelbh/miniconda3/envs/env1/lib/python3.9/site-packages/qiskit_ibm_provider/ibm_backend.py", line 247, in __getattr__
    return self._configuration.__getattribute__(name)
  File "/home/yaelbh/miniconda3/envs/env1/lib/python3.9/site-packages/qiskit_ibm_provider/ibm_backend.py", line 247, in __getattr__
    return self._configuration.__getattribute__(name)
  [Previous line repeated 987 more times]

Printing name at the beginning of __getattr__:

__deepcopy__
__getstate__
__setstate__
_configuration
_configuration
_configuration
_configuration
_configuration
_configuration
_configuration
... and so on

I don't understand why deepcopy reaches __getattr__, and why the recursion occurs. I noticed that the fix suggested in this PR seems to work: the backend's copy is created without exceptions and runs correctly. However, since I don't really understand what's going on, I can't guarantee that the copying worked flawlessly (and that in general adding _configuration to the list does not break anything).

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5114036396

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 50.232%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit_ibm_provider/ibm_backend.py 0 1 0.0%
Totals Coverage Status
Change from base Build 5082667566: 0.0%
Covered Lines: 3033
Relevant Lines: 6038

💛 - Coveralls

@yaelbh
Copy link
Author

yaelbh commented Jun 7, 2023

Closing, I think it's better if a team member who understand the full picture does it. Opened #654 for this purpose.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants