Skip to content

Fix EncryptedType round-trip for sqlalchemy.types.JSON - #832

Open
00200200 wants to merge 1 commit into
kvesteri:masterfrom
00200200:fix/encrypted-type-sqlalchemy-json
Open

00200200 wants to merge 1 commit into
kvesteri:masterfrom
00200200:fix/encrypted-type-sqlalchemy-json

Conversation

@00200200

Copy link
Copy Markdown

Summary

  • Fixes ValueError in EncryptedType.process_result_value with JSON Column #789: EncryptedType / StringEncryptedType with sqlalchemy.types.JSON raised ValueError: dictionary update sequence element #0 has length 1; 2 is required on read.
  • sa.JSON has no process_bind_param / process_result_value (it uses dialect processors), so the AttributeError fallback called dict(json_string). Only JSONType was handled via json.dumps / json.loads.
  • Treat sqlalchemy.types.JSON (and subclasses such as dialect JSON/JSONB) like JSONType for encrypt/decrypt serialization.

Test plan

  • Reproduced the issue script from ValueError in EncryptedType.process_result_value with JSON Column #789 against current master (fails with ValueError).
  • pytest tests/types/test_encrypted.py::TestSqlalchemyJsonEncryptedType — 4 passed (dict and list payloads × StringEncryptedType / EncryptedType).
  • pytest tests/types/test_encrypted.py::TestAesEncryptedTypeWithPKCS5Padding — 13 passed (includes existing JSONType coverage).
  • pytest tests/types/test_encrypted.py::TestFernetEncryptedTypeTestCase::test_json — passed.

sa.JSON uses bind_processor rather than process_bind_param, so the
AttributeError fallback treated decrypted JSON as a dict constructor
argument. Serialize and parse with json instead, matching JSONType.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError in EncryptedType.process_result_value with JSON Column

1 participant