Skip to content

INTPYTHON-929 Encrypted collection existence check (🤖 assisted)#502

Closed
aclark4life wants to merge 2 commits into
mongodb:mainfrom
aclark4life:INTPYTHON-929
Closed

INTPYTHON-929 Encrypted collection existence check (🤖 assisted)#502
aclark4life wants to merge 2 commits into
mongodb:mainfrom
aclark4life:INTPYTHON-929

Conversation

@aclark4life

Copy link
Copy Markdown
Collaborator

Optimize the encrypted field validation by caching collection existence checks. Previously, every insert operation for models with encrypted fields would call table_names() to verify the collection exists. Now, the check is performed once per collection and cached for subsequent inserts.

Changes:

  • Add _verified_encrypted_collections cache set to DatabaseWrapper
  • Check cache before calling table_names() in SQLInsertCompiler.insert()
  • Populate cache when creating encrypted collections in schema editor
  • Add test to verify caching behavior works correctly

This reduces database calls from N (one per insert) to 1 (one per collection) while maintaining the same safety guarantee against unencrypted collection auto-creation.

Optimize the encrypted field validation by caching collection existence
checks. Previously, every insert operation for models with encrypted fields
would call table_names() to verify the collection exists. Now, the check is
performed once per collection and cached for subsequent inserts.

Changes:
- Add _verified_encrypted_collections cache set to DatabaseWrapper
- Check cache before calling table_names() in SQLInsertCompiler.insert()
- Populate cache when creating encrypted collections in schema editor
- Add test to verify caching behavior works correctly

This reduces database calls from N (one per insert) to 1 (one per collection)
while maintaining the same safety guarantee against unencrypted collection
auto-creation.
Remove unittest.mock usage and test the cache behavior directly by
checking the _verified_encrypted_collections set before and after
inserts. This follows the pattern used in other encryption tests.
@aclark4life aclark4life changed the title Cache encrypted collection existence check (🤖 assisted) Encrypted collection existence check (🤖 assisted) Mar 4, 2026
@aclark4life aclark4life changed the title Encrypted collection existence check (🤖 assisted) INTPYTHON-929 Encrypted collection existence check (🤖 assisted) Mar 4, 2026
@aclark4life aclark4life closed this Mar 9, 2026
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.

1 participant