-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: patch FieldInfo for comment support
- Introduce a patch to SQLAlchemy's FieldInfo to support comments, ensuring `sa_column_kwargs` is initialized when not provided. - Enable previously disabled test cases related to column comments by applying the new patch. Generated-by: aiautocommit
- Loading branch information
1 parent
3fd67e6
commit e85d154
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from sqlmodel.main import FieldInfo | ||
|
||
|
||
def hash_function_code(func): | ||
"get sha of a function to easily assert that it hasn't changed" | ||
|
||
import hashlib | ||
import inspect | ||
|
||
source = inspect.getsource(func) | ||
return hashlib.sha256(source.encode()).hexdigest() | ||
|
||
|
||
assert ( | ||
hash_function_code(FieldInfo.__init__) | ||
== "0d947d2aace56b61b7f7bcbea079488b5fb9a1eb9671536c57b06013799e19b0" | ||
) | ||
|
||
original_init = FieldInfo.__init__ | ||
|
||
|
||
def patched_init(self, *args, **kwargs): | ||
if "sa_column" not in kwargs and "sa_column_kwargs" not in kwargs: | ||
kwargs["sa_column_kwargs"] = {} | ||
|
||
original_init(self, *args, **kwargs) | ||
|
||
|
||
FieldInfo.__init__ = patched_init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters