You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge fix-1.3.0 branch with correct Model | None implementation (1.3.4)
This merge brings the correct implementation of Model | None handling,
superseding the incomplete implementations in versions 1.3.1, 1.3.2, and 1.3.3.
Version 1.3.4 is now the recommended version for all users.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+16-32Lines changed: 16 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,44 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
-
### Added
11
-
-**Yield Logging**: Added debug logging for commands yielded from component methods during event handling. Logs format: `< YIELD: ComponentName.method_name -> Command(...)`. Helps developers track command flow and debug issues when components emit multiple commands.
12
-
13
-
### Fixed
14
-
-**Type Safety**: Fixed pyright type errors in introspection and utils modules:
15
-
- Changed `PydanticCustomError` to use literal string template instead of f-string for LiteralString type compatibility
16
-
- Added None check for `app_config.module` in `autodiscover_htmx_modules()` to prevent AttributeError
10
+
## [1.3.4] - 2026-01-19
17
11
18
-
## [1.3.3] - 2026-01-14
19
-
20
-
### Fixed
21
-
-**Lazy Model Deleted Object Handling**: Fixed lazy models to gracefully handle deleted database objects:
22
-
- Required lazy models (`Annotated[Model, ModelConfig(lazy=True)]`): Raise clear `ObjectDoesNotExist` exception when checking truthiness if object was deleted
23
-
- Optional lazy models (`Annotated[Model | None, ModelConfig(lazy=True)]`): Become falsy and return `None` for field accesses when object was deleted
24
-
- Accessing `.pk` on lazy proxies always works without triggering database queries, even for deleted objects
25
-
-**ModelConfig Extraction**: Fixed `annotate_model()` to properly extract and apply `ModelConfig` from `Annotated` type metadata. Previously, `ModelConfig` in annotations like `Annotated[Item, ModelConfig(lazy=True)]` was ignored.
12
+
**Note**: This release supersedes versions 1.3.1, 1.3.2, and 1.3.3, which contained incomplete implementations of the `Model | None` handling feature. Users on 1.3.1-1.3.3 should upgrade to 1.3.4 immediately.
26
13
27
14
### Added
28
-
- Comprehensive test coverage for lazy model deleted object handling using real `HtmxComponent` with user-facing API
29
-
-`__bool__()` method on `_LazyModelProxy` to detect deleted objects immediately when checking truthiness
30
-
31
-
## [1.3.2] - 2026-01-14
32
-
33
-
### Fixed
34
-
-**Generic Type Handling**: Fixed `annotate_model()` to preserve non-Model generic types (like `defaultdict`, `list`, `dict`) when used with `Annotated` wrappers. Previously, these types would be incorrectly transformed to `None`, causing validation errors.
35
-
36
-
## [1.3.1] - 2026-01-14
15
+
-**Yield Logging**: Added debug logging for commands yielded from component methods during event handling. Logs format: `< YIELD: ComponentName.method_name -> Command(...)`. Helps developers track command flow and debug issues when components emit multiple commands.
16
+
- Comprehensive test coverage for `Model | None` and lazy model handling with 12 new tests
37
17
38
18
### Fixed
39
-
-**Optional Model Loading**: Fixed `Model | None` annotations to return `None` when an object with the provided ID doesn't exist (e.g., was deleted), instead of raising `DoesNotExist` exception. Uses `.filter().first()` approach for graceful handling of missing objects.
19
+
-**Model | None Handling**: Fixed components with `Model | None` fields to gracefully return `None` when objects don't exist or have been deleted, instead of raising `DoesNotExist` exceptions
20
+
- Changed database lookups from `manager.get()` to `manager.filter().first()` for graceful handling
21
+
- For optional fields (`Model | None`), returns `None` when object doesn't exist
22
+
- For required fields (`Model`), raises clear `ValueError` with descriptive message
23
+
- Works correctly with both eager and lazy loading (`ModelConfig(lazy=True)`)
24
+
- Lazy models create proxies that handle non-existent objects when attributes are accessed
25
+
-**Type Safety**: Added None check for `app_config.module` in `autodiscover_htmx_modules()` to prevent AttributeError
40
26
41
-
### Added
42
-
- Comprehensive test coverage for optional model handling in both lazy and non-lazy loading scenarios
43
-
- Documentation for model loading optimization (lazy loading, `select_related`, `prefetch_related`) in README
44
-
45
-
### Changed
46
-
- Query parameter handling now preserves full annotation metadata for proper serialization of `Model | None` fields
47
-
- Enhanced `is_basic_type()` to recognize `Model | None` unions as valid simple types for query parameters
27
+
### Technical Details
28
+
- Added `allow_none` parameter to `_ModelBeforeValidator` and `_LazyModelProxy` classes
29
+
- Enhanced `annotate_model()` to detect `Model | None` unions and pass `allow_none=True`
30
+
- Updated lazy proxy `__ensure_instance()` to use `filter().first()` and handle missing objects gracefully
31
+
- QuerySet fields continue to work correctly by silently filtering out non-existent IDs
0 commit comments