Skip to content

Commit 1c3be88

Browse files
use md5 for component id generation (#127)
1 parent 1d8dcb3 commit 1c3be88

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ and this project attempts to adhere to [Semantic Versioning](https://semver.org/
1818

1919
## [Unreleased]
2020

21+
### Changed
22+
23+
- **Internal**: Changed component ID generation to use MD5 hash of name, path, and normalized source instead of Python's built-in hash function. This provides more consistent IDs across different Python processes.
24+
2125
## [0.11.0]
2226

2327
### Added

src/django_bird/components.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from dataclasses import dataclass
44
from dataclasses import field
5+
from hashlib import md5
56
from pathlib import Path
67
from typing import Any
78

@@ -37,14 +38,20 @@ def render(self, context: dict[str, Any]):
3738

3839
@property
3940
def id(self):
40-
whitespace_normalized_source = "".join(self.source.split())
41-
hashed = hash((self.name, whitespace_normalized_source))
42-
return f"{hashed & 0xFFFFFFF:07x}"
41+
normalized_source = "".join(self.source.split())
42+
hashed = md5(
43+
f"{self.name}:{self.path}:{normalized_source}".encode()
44+
).hexdigest()
45+
return hashed[:7]
4346

4447
@property
4548
def nodelist(self):
4649
return self.template.template.nodelist
4750

51+
@property
52+
def path(self):
53+
return self.template.template.origin.name
54+
4855
@property
4956
def source(self):
5057
return self.template.template.source

0 commit comments

Comments
 (0)