surreal-orm-lite 0.50.7__tar.gz → 0.50.8__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 (70) hide show
  1. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/CHANGELOG.md +16 -0
  2. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/PKG-INFO +1 -1
  3. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/pyproject.toml +1 -1
  4. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/__init__.py +1 -1
  5. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/model_base.py +32 -9
  6. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/utils.py +17 -4
  7. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/.gitignore +0 -0
  8. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/LICENSE +0 -0
  9. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/Makefile +0 -0
  10. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/README.md +0 -0
  11. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/docs/README.md +0 -0
  12. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/_client.py +0 -0
  13. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/_sdk.py +0 -0
  14. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/aggregations.py +0 -0
  15. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/auth.py +0 -0
  16. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/cache.py +0 -0
  17. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/changefeed.py +0 -0
  18. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/cli/__init__.py +0 -0
  19. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/cli/__main__.py +0 -0
  20. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/cli/commands.py +0 -0
  21. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/concurrency.py +0 -0
  22. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/connection_config.py +0 -0
  23. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/connection_manager.py +0 -0
  24. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/constants.py +0 -0
  25. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/decoding.py +0 -0
  26. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/define_parser.py +0 -0
  27. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/edge.py +0 -0
  28. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/embedded.py +0 -0
  29. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/encoding.py +0 -0
  30. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/enum.py +0 -0
  31. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/exceptions.py +0 -0
  32. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/functions.py +0 -0
  33. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/geo.py +0 -0
  34. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/hybrid.py +0 -0
  35. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/introspection.py +0 -0
  36. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/live.py +0 -0
  37. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/__init__.py +0 -0
  38. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/autodetect.py +0 -0
  39. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/compare.py +0 -0
  40. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/constants.py +0 -0
  41. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/executor.py +0 -0
  42. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/generator.py +0 -0
  43. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/introspector.py +0 -0
  44. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/loader.py +0 -0
  45. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/migration.py +0 -0
  46. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/operations.py +0 -0
  47. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/render.py +0 -0
  48. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/migrations/state.py +0 -0
  49. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/model_auth.py +0 -0
  50. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/model_ddl.py +0 -0
  51. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/model_generator.py +0 -0
  52. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/py.typed +0 -0
  53. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/q.py +0 -0
  54. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/query_set.py +0 -0
  55. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/routing.py +0 -0
  56. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/schema.py +0 -0
  57. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/schema_state.py +0 -0
  58. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/search.py +0 -0
  59. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/signals.py +0 -0
  60. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/subquery.py +0 -0
  61. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/surql_literal.py +0 -0
  62. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/testing/__init__.py +0 -0
  63. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/testing/database.py +0 -0
  64. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/testing/factories.py +0 -0
  65. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/testing/fixtures.py +0 -0
  66. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/testing/pytest_plugin.py +0 -0
  67. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/time_travel.py +0 -0
  68. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/transaction.py +0 -0
  69. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/types.py +0 -0
  70. {surreal_orm_lite-0.50.7 → surreal_orm_lite-0.50.8}/src/surreal_orm_lite/vector.py +0 -0
@@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.50.8] - 2026-11-18
9
+
10
+ ### Fixed
11
+
12
+ - `update()` and `upsert()` of a model with a `Computed` field whose column has a non-optional `TYPE` and a `VALUE`
13
+ clause (`TYPE datetime VALUE time::now()`, as `generate_models_from_db()` produces) no longer fail on SurrealDB 2.x
14
+ with `Found NONE for field ...` ([#267](https://github.com/EulogySnowfall/SurrealDB-ORM-lite/issues/267)). 2.x checks
15
+ the `TYPE` before the `VALUE` clause runs, so on 2.x the replace now writes each computed column back as its stored
16
+ value and the `VALUE` clause recomputes it. SurrealDB 3.x, 4.x and the embedded engine are unchanged.
17
+
18
+ ### Notes
19
+
20
+ - On 2.x a `VALUE` expression that reads `$value` sees the stored value during a replace, and `NONE` on 3.x; see the
21
+ [models guide](https://github.com/EulogySnowfall/SurrealDB-ORM-lite/blob/main/docs/models.md) and the 2.x vs 3.x
22
+ table in the compatibility guide.
23
+
8
24
  ## [0.50.6] - 2026-11-15
9
25
 
10
26
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: surreal-orm-lite
3
- Version: 0.50.7
3
+ Version: 0.50.8
4
4
  Summary: Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation.
5
5
  Project-URL: Homepage, https://github.com/EulogySnowfall/SurrealDB-ORM-lite
6
6
  Project-URL: Documentation, https://github.com/EulogySnowfall/SurrealDB-ORM-lite
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "surreal-orm-lite"
3
- version = "0.50.7"
3
+ version = "0.50.8"
4
4
  description = "Lightweight Django-style ORM for SurrealDB using the official Python SDK. Async support with Pydantic validation."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -1,4 +1,4 @@
1
- __version__ = "0.50.7"
1
+ __version__ = "0.50.8"
2
2
 
3
3
  from ._sdk import BoundExcluded, BoundIncluded
4
4
  from .aggregations import Aggregation, Avg, Count, Max, Min, Sum
@@ -3383,6 +3383,8 @@ class BaseSurrealModel(BaseModel):
3383
3383
  - **Computed fields** are excluded always. ``DEFINE FIELD … VALUE`` re-evaluates on
3384
3384
  every write, create and replace alike, so sending one is at best wasted bytes and at
3385
3385
  worst — if the definition has not been applied yet — a ``None`` that nulls the column.
3386
+ On SurrealDB 2.x a replace writes them back as their stored value in the statement
3387
+ instead (:meth:`_replace_stored_columns`, #267), never the instance's value.
3386
3388
  - **``server_fields``** are excluded from a **create** only. There, omitting the column
3387
3389
  is precisely how the server's ``DEFAULT`` gets to apply. In a **replace**
3388
3390
  (``UPDATE``/``UPSERT … CONTENT``) omission does not mean "server, fill this in": a
@@ -3406,6 +3408,26 @@ class BaseSurrealModel(BaseModel):
3406
3408
  excluded |= self.get_server_fields() - set(keep)
3407
3409
  return self._columns_for(self.model_dump(exclude=excluded))
3408
3410
 
3411
+ @classmethod
3412
+ async def _replace_stored_columns(cls) -> tuple[str, ...]:
3413
+ """The columns a full replace (``update()``, ``upsert()``) writes back as their stored value (#267).
3414
+
3415
+ The computed columns, on SurrealDB 2.x only (the line read once per client, ``time_travel.cached_major()``).
3416
+ 2.x checks a column's ``TYPE`` against the value a replace gives it **before** its ``VALUE`` clause runs: a
3417
+ computed column left out of ``CONTENT`` is ``NONE``, which a non-optional ``TYPE`` refuses. Written back as
3418
+ ``$this[column]`` (see :func:`~surreal_orm_lite.utils.replace_content`), it passes the check and the ``VALUE``
3419
+ clause recomputes it — an expression reading ``$value`` sees the stored value there. From SurrealDB 3 on (the
3420
+ embedded engine included) and for a model without computed fields: none, no request, the column left out as
3421
+ before. Measured on 2.7.0, 3.3.5 and 4.0.1.
3422
+ """
3423
+ computed = cls.get_computed_fields()
3424
+ if not computed:
3425
+ return ()
3426
+ client = await cls._connection_manager().get_client()
3427
+ if await _time_travel.cached_major(client) >= 3:
3428
+ return ()
3429
+ return tuple(cls._columns_for(dict.fromkeys(computed)))
3430
+
3409
3431
  @classmethod
3410
3432
  def _is_write_protected(cls, name: str) -> bool:
3411
3433
  """Whether ``name`` addresses one of :meth:`_write_protected_fields` (v0.22.0).
@@ -4046,7 +4068,7 @@ class BaseSurrealModel(BaseModel):
4046
4068
  # RETURN $before, $after reports both states of the row in a single statement, so
4047
4069
  # `created` is the truth rather than an assumption (issue #156). Verified on
4048
4070
  # SurrealDB 2.6.x and 3.x alike.
4049
- content, bound = replace_content(data)
4071
+ content, bound = replace_content(data, stored=await self._replace_stored_columns())
4050
4072
  statement = f"UPSERT $rid CONTENT {content} RETURN $before AS before, $after AS after;"
4051
4073
  variables = {"rid": record_id, **bound}
4052
4074
 
@@ -4084,9 +4106,8 @@ class BaseSurrealModel(BaseModel):
4084
4106
  Runs ``UPSERT $rid CONTENT $data``, the record id bound as a query parameter: this is
4085
4107
  REPLACE semantics, so any field omitted from the model is removed from the stored
4086
4108
  record. For a partial update use ``merge()`` instead. An explicit id is required.
4087
- A ``datetime`` written back unchanged keeps the stored nanoseconds, as in :meth:`update`;
4088
- as there, SurrealDB 2.x refuses to replace an existing record when the model leaves out a
4089
- field with a non-optional ``TYPE`` and a ``VALUE`` clause, a ``Computed`` one (#267).
4109
+ A ``datetime`` written back unchanged keeps the stored nanoseconds, and on SurrealDB 2.x a
4110
+ ``Computed`` column is written back as its stored value, as in :meth:`update` (#267).
4090
4111
 
4091
4112
  When ``tx`` is provided, the ``UPSERT`` is buffered onto the transaction.
4092
4113
 
@@ -4141,10 +4162,12 @@ class BaseSurrealModel(BaseModel):
4141
4162
  :func:`~surreal_orm_lite.utils.replace_content`. Without a datetime to keep, the statement
4142
4163
  is the SDK's ``update()``, as before.
4143
4164
 
4144
- SurrealDB 2.x still refuses a full replace that leaves out a field declared with a
4145
- non-optional ``TYPE`` and a ``VALUE`` clause, which the model does not write (a
4146
- ``Computed`` field, such as a generated ``updated: Computed[datetime]``): there, change
4147
- such a record with :meth:`merge` (#267). SurrealDB 3.x recomputes the field.
4165
+ A ``Computed`` field is not written from the instance. SurrealDB 2.x checks a column's
4166
+ ``TYPE`` before its ``VALUE`` clause runs, so a computed column with a non-optional ``TYPE``
4167
+ (a generated ``updated: Computed[datetime]``) left out refused the replace: on 2.x it is
4168
+ written back as its stored value (``$this``) and the ``VALUE`` clause recomputes it (#267,
4169
+ the server line read once per client). From SurrealDB 3 on it is left out and recomputed.
4170
+ An expression reading ``$value`` therefore sees the stored value on 2.x, ``NONE`` on 3.x.
4148
4171
 
4149
4172
  Emits pre_update, post_update, and around_update signals. In tx mode,
4150
4173
  ``around_update`` is skipped (the write is deferred to commit) and
@@ -4172,7 +4195,7 @@ class BaseSurrealModel(BaseModel):
4172
4195
  data = self._write_payload(replace=True)
4173
4196
  record_id = self._record_id()
4174
4197
  assert record_id is not None # refused by _update_arguments() (#320)
4175
- content, bound = replace_content(data)
4198
+ content, bound = replace_content(data, stored=await self._replace_stored_columns())
4176
4199
 
4177
4200
  has_signals = pre_update.has_handlers(sender) or post_update.has_handlers(sender) or around_update.has_handlers(sender)
4178
4201
 
@@ -360,7 +360,7 @@ def _keep_plan(value: Any, depth: int, left: int) -> tuple[_KeepPlan | None, int
360
360
  return plans, cost
361
361
 
362
362
 
363
- def replace_content(data: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
363
+ def replace_content(data: Mapping[str, Any], stored: Collection[str] = ()) -> tuple[str, dict[str, Any]]:
364
364
  """Compile the ``CONTENT`` of a full replace (``UPDATE``/``UPSERT $rid CONTENT …``) of ``data`` (#261).
365
365
 
366
366
  SurrealDB stores datetimes to the nanosecond, the SDK reads them floored to the microsecond: writing a
@@ -383,13 +383,23 @@ def replace_content(data: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
383
383
  written as sent. Anything past the budget (a long list, a large sub-object, a deeper datetime) is bound whole and
384
384
  written as sent, and so is a set, whose items have no position to match a stored value by.
385
385
 
386
+ Each column of ``stored`` that ``data`` does not hold is written as its stored value, ``$this[$cN]`` (``NONE`` when
387
+ the record has none, or does not exist yet), after the entries of ``data`` (#267). ``update()``/``upsert()`` pass a
388
+ model's computed columns there on SurrealDB 2.x only: that line checks a column's ``TYPE`` against the value a
389
+ replace gives it **before** its ``VALUE`` clause runs, so a computed column with a non-optional ``TYPE`` left out
390
+ (``NONE``) refused the write; written back, it passes the check and the ``VALUE`` clause recomputes it::
391
+
392
+ replace_content({"name": "Ada"}, stored=("updated",))
393
+ # ("object::from_entries([[$c0, $c1], [$c2, $this[$c2]]])", {"c0": "name", "c1": "Ada", "c2": "updated"})
394
+
386
395
  Returns:
387
396
  The expression and the variables to bind alongside it: ``(PLAIN_CONTENT, {"data": data})`` when it keeps no
388
- stored datetime (``data`` holds none within those bounds, or has a key that is not a ``str``), the statement
389
- of before #261.
397
+ stored value (``data`` holds no datetime within those bounds and ``stored`` adds no column, or ``data`` has a
398
+ key that is not a ``str``), the statement of before #261.
390
399
  """
391
400
  if not all(isinstance(key, str) for key in data):
392
401
  return PLAIN_CONTENT, {"data": data}
402
+ stored = [column for column in stored if column not in data]
393
403
  left = _KEEP_LIMIT
394
404
  plans: dict[str, _KeepPlan] = {}
395
405
  for key, value in data.items():
@@ -402,7 +412,7 @@ def replace_content(data: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
402
412
  if plan is not None:
403
413
  plans[key] = plan
404
414
  left -= cost
405
- if not plans:
415
+ if not plans and not stored:
406
416
  return PLAIN_CONTENT, {"data": data}
407
417
  variables: dict[str, Any] = {}
408
418
 
@@ -433,6 +443,9 @@ def replace_content(data: Mapping[str, Any]) -> tuple[str, dict[str, Any]]:
433
443
  for key, value in data.items():
434
444
  bound = bind(key)
435
445
  entries.append(f"[{bound}, {written(value, plans.get(key), f'$this[{bound}]')}]")
446
+ for column in stored:
447
+ bound = bind(column)
448
+ entries.append(f"[{bound}, $this[{bound}]]")
436
449
  return f"object::from_entries([{', '.join(entries)}])", variables
437
450
 
438
451