Infinite recursion error on deep copy `AzureBackendConfig` due to __getattr__ implementation
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu tại azure-quantum/azure/quantum/qiskit/backends/backend.py, ở AzureBackendConfig.getattr, sau đó chạy bản tái hiện deepcopy từ issue. Xác minh rằng việc sao chép một instance có metadata rỗng không còn gây ra RecursionError, trong khi các thuộc tính bị thiếu vẫn gây ra AttributeError và các thuộc tính dựa trên metadata tiếp tục hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The class AzureBackendConfig in azure.quantum.qiskit.backends.backend has a field metadata containing any remaining properties of the class. The __getattr__ method of this class is implemented in such a way that, if the attribute is not found, the metadata dict is checked. However, this leads to a RecursionError: maximum recursion depth exceeded when an instance of the class is copied using copy.deepcopy (which apparently happens sometimes).
class AzureBackendConfig:
...
def __getattr__(self, name: str) -> Any:
if name == "max_experiments":
return 1
try:
return self.__dict__[name]
except KeyError as exc:
if name in self.metadata:
return self.metadata[name]
raise AttributeError(
f"'{type(self).__name__}' object has no attribute '{name}'"
) from exc
Simplified reproduction of the error:
import copy
from dataclasses import dataclass, field
from typing import Any
@dataclass
class A:
metadata: dict[str, Any] = field(default_factory=dict)
def __getattr__(self, name: str) -> Any:
try:
return self.__dict__[name]
except KeyError as exc:
if name in self.metadata:
return self.metadata[name]
raise AttributeError(
f"'{type(self).__name__}' object has no attribute '{name}'"
) from exc
a = A()
copy.deepcopy(a) # RecursionError: maximum recursion depth exceeded
A possible solution would be to change the problematic line to:
if "metadata" in self.__dict__ and name in self.metadata:
- Ngôn ngữ chính
- Python
- Star
- 162
- Fork
- 113
- Merge trung bình
- 4 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/azure-quantum-python
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
-
Export typesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
microsoft/azure-quantum-python#650 · 1 bình luận ·
-
azure-quantum
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 20/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
microsoft/azure-quantum-python#416 · 3 bình luận ·
Tất cả issue của microsoft/azure-quantum-python
Issue tương tự
-
Claiming namespace `jft63`Đang mởnamespace operations
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
EclipseFdn/open-vsx.org#14043 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
netbox status: needs triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
netbox-community/netbox#23376 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feedback simulation workshop
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
githubnext/gh-aw-workshop#4455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Triage 🩺
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_waitĐang mởneeds-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
krkn-chaos/krkn#1627 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày