django-vcache 2.0.9__tar.gz → 2.0.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. {django_vcache-2.0.9 → django_vcache-2.0.10}/CHANGELOG.md +6 -0
  2. {django_vcache-2.0.9 → django_vcache-2.0.10}/Cargo.lock +5 -5
  3. {django_vcache-2.0.9 → django_vcache-2.0.10}/Cargo.toml +1 -1
  4. {django_vcache-2.0.9 → django_vcache-2.0.10}/PKG-INFO +1 -1
  5. {django_vcache-2.0.9 → django_vcache-2.0.10}/pyproject.toml +1 -1
  6. {django_vcache-2.0.9 → django_vcache-2.0.10}/src/async_bridge.rs +36 -7
  7. {django_vcache-2.0.9 → django_vcache-2.0.10}/uv.lock +1 -1
  8. {django_vcache-2.0.9 → django_vcache-2.0.10}/.dockerignore +0 -0
  9. {django_vcache-2.0.9 → django_vcache-2.0.10}/.gitignore +0 -0
  10. {django_vcache-2.0.9 → django_vcache-2.0.10}/.gitlab-ci.yml +0 -0
  11. {django_vcache-2.0.9 → django_vcache-2.0.10}/AGENTS.md +0 -0
  12. {django_vcache-2.0.9 → django_vcache-2.0.10}/CLAUDE.md +0 -0
  13. {django_vcache-2.0.9 → django_vcache-2.0.10}/Dockerfile +0 -0
  14. {django_vcache-2.0.9 → django_vcache-2.0.10}/LICENSE +0 -0
  15. {django_vcache-2.0.9 → django_vcache-2.0.10}/README.md +0 -0
  16. {django_vcache-2.0.9 → django_vcache-2.0.10}/bench_asgi.sh +0 -0
  17. {django_vcache-2.0.9 → django_vcache-2.0.10}/bench_compare.py +0 -0
  18. {django_vcache-2.0.9 → django_vcache-2.0.10}/bench_slowpath.sh +0 -0
  19. {django_vcache-2.0.9 → django_vcache-2.0.10}/benchmark.py +0 -0
  20. {django_vcache-2.0.9 → django_vcache-2.0.10}/compose.cluster.yml +0 -0
  21. {django_vcache-2.0.9 → django_vcache-2.0.10}/compose.sentinel.yml +0 -0
  22. {django_vcache-2.0.9 → django_vcache-2.0.10}/compose.tls.yml +0 -0
  23. {django_vcache-2.0.9 → django_vcache-2.0.10}/compose.yml +0 -0
  24. {django_vcache-2.0.9 → django_vcache-2.0.10}/django_vcache/__init__.py +0 -0
  25. {django_vcache-2.0.9 → django_vcache-2.0.10}/django_vcache/backend.py +0 -0
  26. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/benchmarks.md +0 -0
  27. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/configuration.md +0 -0
  28. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/contributing.md +0 -0
  29. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/getting-started.md +0 -0
  30. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/guide.md +0 -0
  31. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/index.md +0 -0
  32. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/overrides/extra.css +0 -0
  33. {django_vcache-2.0.9 → django_vcache-2.0.10}/docs/overrides/main.html +0 -0
  34. {django_vcache-2.0.9 → django_vcache-2.0.10}/manage.py +0 -0
  35. {django_vcache-2.0.9 → django_vcache-2.0.10}/mkdocs.yml +0 -0
  36. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/__init__.py +0 -0
  37. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/asgi.py +0 -0
  38. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/management/__init__.py +0 -0
  39. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/management/commands/__init__.py +0 -0
  40. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/management/commands/benchmark.py +0 -0
  41. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/management/commands/memtest.py +0 -0
  42. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/settings.py +0 -0
  43. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/settings_bench.py +0 -0
  44. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/settings_django.py +0 -0
  45. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/settings_v1.py +0 -0
  46. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/test_sentinel_blocking.py +0 -0
  47. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/tests.py +0 -0
  48. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/tests_chaos.py +0 -0
  49. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/tests_exceptions.py +0 -0
  50. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/tests_fork.py +0 -0
  51. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/urls.py +0 -0
  52. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/views.py +0 -0
  53. {django_vcache-2.0.9 → django_vcache-2.0.10}/sample/wsgi.py +0 -0
  54. {django_vcache-2.0.9 → django_vcache-2.0.10}/src/client.rs +0 -0
  55. {django_vcache-2.0.9 → django_vcache-2.0.10}/src/connection.rs +0 -0
  56. {django_vcache-2.0.9 → django_vcache-2.0.10}/src/lib.rs +0 -0
  57. {django_vcache-2.0.9 → django_vcache-2.0.10}/tls/generate-certs.sh +0 -0
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.10
4
+
5
+ ### Bug fixes
6
+
7
+ - **Fix contextvars corruption in callback mode** — `add_done_callback` discarded the `context` parameter, and `_wake` invoked callbacks without their associated context. When an async cache operation took longer than 5 event loop polls (triggering callback mode), asyncio's `Task.__step` was called without the task's `contextvars.Context`. This caused `ContextVar.reset(token)` to raise `ValueError: was created in a different Context` in downstream middleware (e.g. allauth's `AccountMiddleware`). Done-callbacks are now stored as `(callback, context)` pairs and invoked via `context.run(callback, self)`, matching `asyncio.Future`'s contract.
8
+
3
9
  ## 2.0.7
4
10
 
5
11
  ### Bug fixes
@@ -68,9 +68,9 @@ checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"
68
68
 
69
69
  [[package]]
70
70
  name = "cc"
71
- version = "1.2.56"
71
+ version = "1.2.57"
72
72
  source = "registry+https://github.com/rust-lang/crates.io-index"
73
- checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2"
73
+ checksum = "7a0dd1ca384932ff3641c8718a02769f1698e7563dc6974ffd03346116310423"
74
74
  dependencies = [
75
75
  "find-msvc-tools",
76
76
  "jobserver",
@@ -142,7 +142,7 @@ dependencies = [
142
142
 
143
143
  [[package]]
144
144
  name = "django-vcache"
145
- version = "2.0.9"
145
+ version = "2.0.10"
146
146
  dependencies = [
147
147
  "pyo3",
148
148
  "redis",
@@ -435,9 +435,9 @@ dependencies = [
435
435
 
436
436
  [[package]]
437
437
  name = "once_cell"
438
- version = "1.21.3"
438
+ version = "1.21.4"
439
439
  source = "registry+https://github.com/rust-lang/crates.io-index"
440
- checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
440
+ checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
441
441
 
442
442
  [[package]]
443
443
  name = "openssl-probe"
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "django-vcache"
3
- version = "2.0.9"
3
+ version = "2.0.10"
4
4
  edition = "2024"
5
5
  readme = "README.md"
6
6
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-vcache
3
- Version: 2.0.9
3
+ Version: 2.0.10
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Framework :: Django
6
6
  Classifier: Framework :: Django :: 5.0
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "django-vcache"
7
- version = "2.0.9"
7
+ version = "2.0.10"
8
8
  description = "A specialized, lightweight Django cache backend for Valkey."
9
9
  readme = "README.md"
10
10
  authors = [{ name = "David Burke", email = "david@burkesoftware.com" }]
@@ -146,12 +146,21 @@ impl RawResult {
146
146
  // - Idle: zero CPU (no busy-yield loops)
147
147
  // =========================================================================
148
148
 
149
+ /// A done-callback with its associated context, matching asyncio's
150
+ /// `add_done_callback(fn, *, context=ctx)` protocol. Storing the context
151
+ /// ensures callbacks run in the correct `contextvars.Context`, which is
152
+ /// critical for middleware that uses `ContextVar.reset(token)`.
153
+ struct DoneCallback {
154
+ callback: Py<PyAny>,
155
+ context: Option<Py<PyAny>>,
156
+ }
157
+
149
158
  /// Callback-mode state — only allocated when an operation doesn't resolve
150
159
  /// within the busy-yield window (5 polls). Most fast ops never need this,
151
160
  /// so keeping it boxed avoids bloating every RustAwaitable allocation.
152
161
  struct CallbackState {
153
162
  event_loop: Py<PyAny>,
154
- callbacks: Vec<Py<PyAny>>,
163
+ callbacks: Vec<DoneCallback>,
155
164
  result_slot: Arc<Mutex<Option<Result<RawResult, ()>>>>,
156
165
  }
157
166
 
@@ -346,6 +355,11 @@ impl RustAwaitable {
346
355
 
347
356
  /// Called on the event loop thread via call_soon_threadsafe.
348
357
  /// Fires done-callbacks so the Task can resume.
358
+ ///
359
+ /// Each callback is invoked via `context.run(callback, self)` when a
360
+ /// context was provided by `add_done_callback`, matching asyncio.Future's
361
+ /// contract. This ensures the callback (typically `Task.__step`) runs
362
+ /// in the correct `contextvars.Context`.
349
363
  fn _wake(slf: Py<Self>, py: Python<'_>) {
350
364
  let callbacks = {
351
365
  let mut this = slf.borrow_mut(py);
@@ -354,16 +368,22 @@ impl RustAwaitable {
354
368
  .map(|cb| std::mem::take(&mut cb.callbacks))
355
369
  .unwrap_or_default()
356
370
  };
357
- for cb in callbacks {
358
- let _ = cb.call1(py, (&slf,));
371
+ for done_cb in callbacks {
372
+ if let Some(ref ctx) = done_cb.context {
373
+ let _ = ctx.call_method1(py, "run", (&done_cb.callback, &slf));
374
+ } else {
375
+ let _ = done_cb.callback.call1(py, (&slf,));
376
+ }
359
377
  }
360
378
  }
361
379
 
362
380
  #[pyo3(signature = (fn_cb, *, context=None))]
363
381
  fn add_done_callback(&mut self, fn_cb: Py<PyAny>, context: Option<Py<PyAny>>) {
364
- let _ = context;
365
382
  if let Some(ref mut cb) = self.cb {
366
- cb.callbacks.push(fn_cb);
383
+ cb.callbacks.push(DoneCallback {
384
+ callback: fn_cb,
385
+ context,
386
+ });
367
387
  }
368
388
  // If no callback state yet (still in busy-yield), the callback
369
389
  // will be added when we enter callback mode. In practice, asyncio
@@ -413,8 +433,17 @@ impl RustAwaitable {
413
433
  let cb_state = this.cb.take();
414
434
  drop(this);
415
435
  if let Some(cb) = cb_state {
416
- for callback in cb.callbacks {
417
- let _ = cb.event_loop.call_method1(py, "call_soon", (&callback, slf.bind(py)));
436
+ for done_cb in cb.callbacks {
437
+ let kwargs = pyo3::types::PyDict::new(py);
438
+ if let Some(ref ctx) = done_cb.context {
439
+ let _ = kwargs.set_item("context", ctx);
440
+ }
441
+ let _ = cb.event_loop.call_method(
442
+ py,
443
+ "call_soon",
444
+ (&done_cb.callback, slf.bind(py)),
445
+ Some(&kwargs),
446
+ );
418
447
  }
419
448
  }
420
449
  true
@@ -120,7 +120,7 @@ wheels = [
120
120
 
121
121
  [[package]]
122
122
  name = "django-vcache"
123
- version = "2.0.5"
123
+ version = "2.0.9"
124
124
  source = { editable = "." }
125
125
  dependencies = [
126
126
  { name = "django" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes