Browse Source

Monkeypatch wtforms

Peter Justin 7 years ago
parent
commit
07c7aecd58
1 changed files with 18 additions and 0 deletions
  1. 18 0
      flaskbb/__init__.py

+ 18 - 0
flaskbb/__init__.py

@@ -15,3 +15,21 @@ import logging
 logger = logging.getLogger(__name__)
 
 from flaskbb.app import create_app  # noqa
+
+
+# monkeypatch for https://github.com/wtforms/wtforms/issues/373
+# Taken from https://github.com/indico/indico/commit/c79c562866e5efdbeb5a3101cccc97df57906f76
+def _patch_wtforms_sqlalchemy():
+    from ._compat import text_type
+    from wtforms.ext.sqlalchemy import fields
+    from sqlalchemy.orm.util import identity_key
+
+    def get_pk_from_identity(obj):
+        key = identity_key(instance=obj)[1]
+        return u':'.join(map(text_type, key))
+
+    fields.get_pk_from_identity = get_pk_from_identity
+
+
+_patch_wtforms_sqlalchemy()
+del _patch_wtforms_sqlalchemy