Skip to content

Commit 6752f16

Browse files
committed
warn if pk of editable row contains chars invalid css identifiers
1 parent 5aa6e8c commit 6752f16

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

flask_admin/model/widgets.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import typing as t
23
import warnings
34

@@ -95,6 +96,14 @@ def __call__(self, field: Field, **kwargs: t.Any) -> str:
9596
field_name = escape(field.name)
9697
pk_esc = escape(pk)
9798

99+
if re.search(r"[^\w-]", pk_esc):
100+
warnings.warn(
101+
f"Primary key {str(pk)!r} contains characters that are invalid "
102+
f"in CSS identifiers. Inline editing will not work for this record.",
103+
UserWarning,
104+
stacklevel=1,
105+
)
106+
98107
return Markup(f"""
99108
<span
100109
id="editable-{field_name}-{pk_esc}"

0 commit comments

Comments
 (0)