fix(encryption): Fix encrypted field metrics table_name tag#106957
Merged
vgrozdanic merged 2 commits intomasterfrom Jan 28, 2026
Merged
fix(encryption): Fix encrypted field metrics table_name tag#106957vgrozdanic merged 2 commits intomasterfrom
vgrozdanic merged 2 commits intomasterfrom
Conversation
Previously the model name was not being sent in metrics because: - Used getattr(self, '_model_name', 'unknown') but _model_name was never set - Field had __set_name__ but Django's ModelBase metaclass never calls it - Django removes fields from class dict before Python can call __set_name__ Changes: - Initialize _model_name in __init__ with 'unknown' default - Implement contribute_to_class to capture actual model name - Change metric tag from 'model' to 'table_name' for clarity - Add tests to verify metrics are sent with correct table_name All 68 encryption field tests pass.
vgrozdanic
commented
Jan 28, 2026
| "method": encryption_method, | ||
| "field_type": self.__class__.__name__, | ||
| "model": getattr(self, "_model_name", "unknown"), | ||
| "table_name": self._model_name, |
Member
Author
There was a problem hiding this comment.
changed also the tag name because model is too generic tag
priscilawebdev
pushed a commit
that referenced
this pull request
Feb 2, 2026
Fix encrypted field metrics to properly send the table name in metric tags. The original code implemented `__set_name__()` to capture the model name, expecting Python's descriptor protocol to call it. However, Django's `ModelBase` metaclass removes fields from the class dict and stores them in `_meta` before Python can call `__set_name__()`. Django uses `contribute_to_class()` instead, which the encrypted field wasn't implementing.
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix encrypted field metrics to properly send the table name in metric tags.
The original code implemented
__set_name__()to capture the model name, expecting Python's descriptor protocol to call it. However, Django'sModelBasemetaclass removes fields from the class dict and stores them in_metabefore Python can call__set_name__(). Django usescontribute_to_class()instead, which the encrypted field wasn't implementing.