Skip to content

Commit 0bf3acf

Browse files
committed
πŸ€– Release 0.89.1
Permission extensions are now fully compatible with `strawberry-graphql >= 0.326.0`, which enforces strict type uniqueness for custom schema directives during schema construction. Previously, `DjangoPermissionExtension.schema_directive` created a new anonymous `AutoDirective` class on every extension instantiation without caching it on the underlying class. When the same permission extension (e.g. `IsSuperuser()`, `IsAuthenticated()`, or custom subclasses) was attached to multiple fields, Strawberry raised a `ValueError` reporting duplicate directive definitions for the same directive name. The generated `AutoDirective` class is now cached on `self.__class__` via `__dict__.get()`: ```python @functools.cached_property def schema_directive(self) -> object: key = "__strawberry_directive_type__" directive_class = self.__class__.__dict__.get(key) if directive_class is None: @schema_directive( name=self.__class__.__name__, locations=self.SCHEMA_DIRECTIVE_LOCATIONS, description=self.SCHEMA_DIRECTIVE_DESCRIPTION, repeatable=True, ) class AutoDirective: ... directive_class = AutoDirective setattr(self.__class__, key, directive_class) return directive_class() ``` This ensures a single, reusable schema directive type is created per extension class, eliminating duplicate directive collisions while preserving full isolation across subclasses and maintaining backward compatibility with older Strawberry versions. [skip ci]
1 parent 18df722 commit 0bf3acf

4 files changed

Lines changed: 40 additions & 36 deletions

File tree

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
CHANGELOG
22
=========
33

4+
0.89.1 - 2026-09-13
5+
-------------------
6+
7+
Permission extensions are now fully compatible with `strawberry-graphql >= 0.326.0`, which enforces strict type uniqueness for custom schema directives during schema construction.
8+
9+
Previously, `DjangoPermissionExtension.schema_directive` created a new anonymous `AutoDirective` class on every extension instantiation without caching it on the underlying class.
10+
When the same permission extension (e.g. `IsSuperuser()`, `IsAuthenticated()`, or custom subclasses) was attached to multiple fields, Strawberry raised a `ValueError` reporting duplicate directive definitions for the same directive name.
11+
12+
The generated `AutoDirective` class is now cached on `self.__class__` via `__dict__.get()`:
13+
14+
```python
15+
@functools.cached_property
16+
def schema_directive(self) -> object:
17+
key = "__strawberry_directive_type__"
18+
directive_class = self.__class__.__dict__.get(key)
19+
20+
if directive_class is None:
21+
22+
@schema_directive(
23+
name=self.__class__.__name__,
24+
locations=self.SCHEMA_DIRECTIVE_LOCATIONS,
25+
description=self.SCHEMA_DIRECTIVE_DESCRIPTION,
26+
repeatable=True,
27+
)
28+
class AutoDirective: ...
29+
30+
directive_class = AutoDirective
31+
setattr(self.__class__, key, directive_class)
32+
33+
return directive_class()
34+
```
35+
36+
This ensures a single, reusable schema directive type is created per extension class, eliminating duplicate directive collisions while preserving full isolation across subclasses and maintaining backward compatibility with older Strawberry versions.
37+
38+
This release was contributed by [@daudln](https://github.com/daudln) in [#951](https://github.com/strawberry-graphql/strawberry-django/pull/951)
39+
40+
Additional contributors: [@bellini666](https://github.com/bellini666), [@Copilot](https://github.com/Copilot), [@pre-commit-ci[bot]](https://github.com/pre-commit-ci[bot])
41+
442
0.89.0 - 2026-09-08
543
-------------------
644

β€ŽRELEASE.mdβ€Ž

Lines changed: 0 additions & 34 deletions
This file was deleted.

β€Žpyproject.tomlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "strawberry-graphql-django"
3-
version = "0.89.0"
3+
version = "0.89.1"
44
description = "Strawberry GraphQL Django extension"
55
authors = [
66
{ name = "Lauri Hintsala", email = "lauri.hintsala@verkkopaja.fi" },

β€Žuv.lockβ€Ž

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)