MCPcopy Index your code
hub / github.com/google/adk-python / _stable_model_digest

Function _stable_model_digest

src/google/adk/auth/auth_tool.py:29–48  ·  view source on GitHub ↗

Returns a stable digest for a pydantic model. The digest is stable across: - Python hash seeds (does not use `hash()`). - Dict insertion ordering differences (canonicalizes via `sort_keys=True`). - Pydantic `model_extra` values (ignored).

(model: BaseModel)

Source from the content-addressed store, hash-verified

27
28
29def _stable_model_digest(model: BaseModel) -> str:
30 """Returns a stable digest for a pydantic model.
31
32 The digest is stable across:
33 - Python hash seeds (does not use `hash()`).
34 - Dict insertion ordering differences (canonicalizes via `sort_keys=True`).
35 - Pydantic `model_extra` values (ignored).
36 """
37 if getattr(model, "model_extra", None):
38 model = model.model_copy(deep=True)
39 model.model_extra.clear()
40
41 dumped = model.model_dump(by_alias=True, exclude_none=True, mode="json")
42 canonical_json = json.dumps(
43 dumped,
44 sort_keys=True,
45 ensure_ascii=False,
46 separators=(",", ":"),
47 )
48 return hashlib.sha256(canonical_json.encode("utf-8")).hexdigest()[:16]
49
50
51class AuthConfig(BaseModelWithConfig):

Callers 2

get_credential_keyMethod · 0.85
get_credential_keyMethod · 0.85

Calls 4

getattrFunction · 0.85
model_copyMethod · 0.45
clearMethod · 0.45
model_dumpMethod · 0.45

Tested by

no test coverage detected