Skip to content

Commit

Permalink
Use pessimistic mode for reference many delete (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Jul 31, 2023
1 parent ade847c commit 0ee079b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions admin-js/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const DatagridSingle = (props) => (
const COMPONENTS = {
Datagrid, DatagridSingle,

BulkDeleteButton,

BooleanField, DateField, NumberField, ReferenceField, ReferenceManyField,
ReferenceOneField, SelectField, TextField, TimeField,

Expand Down
3 changes: 3 additions & 0 deletions aiohttp_admin/backends/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ def __init__(self, db: AsyncEngine, model_or_table: Union[sa.Table, type[Declara
children.append(comp(field, c_props))
container = "Datagrid" if t == "ReferenceManyField" else "DatagridSingle"
datagrid = comp(container, {"children": children, "rowClick": "show"})
if t == "ReferenceManyField":
datagrid["props"]["bulkActionButtons"] = comp(
"BulkDeleteButton", {"mutationMode": "pessimistic"})
props["children"] = (datagrid,)

self.fields[name] = comp(t, props)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_backends_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class TestOne(base): # type: ignore[misc,valid-type]
assert r.fields["ones"] == comp(
"ReferenceManyField",
{"children": (comp("Datagrid", {
"rowClick": "show", "children": [comp("NumberField", {"source": "id"})]}),),
"rowClick": "show", "children": [comp("NumberField", {"source": "id"})],
"bulkActionButtons": comp("BulkDeleteButton", {"mutationMode": "pessimistic"})}),),
"label": "Ones", "reference": "one", "source": "id", "target": "many_id",
"sortable": False})
assert "ones" not in r.inputs
Expand Down

0 comments on commit 0ee079b

Please sign in to comment.