Skip to content

Commit 99a1425

Browse files
authored
Fix dictionary size change exception when using SQLAlchemy association_proxy (#624)
* Fix dictionary size change exception when using SQLAlchemy association_proxy * closes #507
1 parent a870676 commit 99a1425

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

starlette_admin/contrib/sqla/view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(
9595
if self.fields is None or len(self.fields) == 0:
9696
self.fields = [
9797
self.model.__dict__[f].key
98-
for f in self.model.__dict__
98+
for f in list(self.model.__dict__.keys())
9999
if type(self.model.__dict__[f]) is InstrumentedAttribute
100100
]
101101
self.fields = (converter or ModelConverter()).convert_fields_list(
@@ -134,7 +134,7 @@ def _setup_primary_key(self) -> None:
134134
Tuple[InstrumentedAttribute, ...], InstrumentedAttribute
135135
] = ()
136136
self._pk_coerce: Union[Tuple[type, ...], type] = ()
137-
for key in self.model.__dict__:
137+
for key in list(self.model.__dict__.keys()):
138138
attr = getattr(self.model, key)
139139
if isinstance(attr, InstrumentedAttribute) and getattr(
140140
attr, "primary_key", False

tests/sqla/test_sync_engine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
select,
2121
)
2222
from sqlalchemy.engine import Engine
23+
from sqlalchemy.ext.associationproxy import association_proxy
2324
from sqlalchemy.orm import Session, declarative_base, relationship
2425
from sqlalchemy_file.storage import StorageManager
2526
from starlette.applications import Starlette
@@ -60,6 +61,8 @@ class User(Base):
6061
name = Column(String(100), primary_key=True)
6162
files = Column(sf.FileField(multiple=True))
6263
products = relationship("Product", back_populates="user")
64+
# to reproduce https://github.com/jowilf/starlette-admin/issues/507
65+
product_titles = association_proxy("products", "titles")
6366

6467

6568
class ProductView(ModelView):

0 commit comments

Comments
 (0)