surreal-orm-lite 0.35.3__tar.gz → 0.35.4__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 (49) hide show
  1. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/CHANGELOG.md +34 -0
  2. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/PKG-INFO +13 -6
  3. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/README.md +12 -5
  4. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/pyproject.toml +1 -1
  5. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/__init__.py +1 -1
  6. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/model_auth.py +16 -4
  7. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/model_base.py +51 -9
  8. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/schema.py +6 -4
  9. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/.gitignore +0 -0
  10. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/LICENSE +0 -0
  11. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/Makefile +0 -0
  12. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/_sdk.py +0 -0
  13. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/aggregations.py +0 -0
  14. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/auth.py +0 -0
  15. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/cache.py +0 -0
  16. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/changefeed.py +0 -0
  17. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/concurrency.py +0 -0
  18. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/connection_config.py +0 -0
  19. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/connection_manager.py +0 -0
  20. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/constants.py +0 -0
  21. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/decoding.py +0 -0
  22. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/define_parser.py +0 -0
  23. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/edge.py +0 -0
  24. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/embedded.py +0 -0
  25. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/encoding.py +0 -0
  26. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/enum.py +0 -0
  27. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/exceptions.py +0 -0
  28. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/functions.py +0 -0
  29. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/geo.py +0 -0
  30. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/introspection.py +0 -0
  31. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/live.py +0 -0
  32. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/model_ddl.py +0 -0
  33. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/model_generator.py +0 -0
  34. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/py.typed +0 -0
  35. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/q.py +0 -0
  36. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/query_set.py +0 -0
  37. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/routing.py +0 -0
  38. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/schema_state.py +0 -0
  39. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/search.py +0 -0
  40. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/signals.py +0 -0
  41. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/subquery.py +0 -0
  42. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/surql_literal.py +0 -0
  43. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/testing/__init__.py +0 -0
  44. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/testing/database.py +0 -0
  45. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/testing/fixtures.py +0 -0
  46. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/time_travel.py +0 -0
  47. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/transaction.py +0 -0
  48. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/types.py +0 -0
  49. {surreal_orm_lite-0.35.3 → surreal_orm_lite-0.35.4}/src/surreal_orm_lite/utils.py +0 -0
@@ -5,6 +5,40 @@ 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.35.4] - 2026-10-23
9
+
10
+ `update()`, `upsert()`, `authenticate()` and `refresh()` refuse an auth model whose signup field
11
+ is declared `Field(exclude=True)`, as the DDL methods, `signup()` and `signin()` do since v0.35.2
12
+ (#310): a record signed up elsewhere and loaded through such a model no longer loses its stored
13
+ password hash at its first `update()` or `upsert()`. No new public API.
14
+
15
+ ### Changed
16
+
17
+ - **`authenticate()`, `refresh()`, `update()` and `upsert()` raise the v0.35.2 `TypeError` for
18
+ an auth model with an excluded signup field** (#310). For a model built on
19
+ `AuthenticatedUserMixin` with a field SIGNUP writes that `Field(exclude=True)` keeps out of
20
+ `model_dump()` (`password: str = Field(exclude=True)`), `update()` and `upsert()` now raise it
21
+ before any request and any `pre_save`/`pre_update` signal, with or without `tx=` (nothing is
22
+ added to the transaction), and `authenticate()` and `refresh()` before any request (a refresh
23
+ token is not spent). The message, `schema.signup_excluded_refused()`, now names every refusing
24
+ call: `table_ddl()`, `define_table()`, `access_ddl()`, `define_access()`, `signup()`,
25
+ `signin()`, `authenticate()`, `refresh()`, `update()` and `upsert()`. Auth models without
26
+ `exclude=True`, and models that are not auth models, write and authenticate as before.
27
+
28
+ ### Fixed
29
+
30
+ - **A record signed up elsewhere no longer loses its password hash at `update()` or `upsert()`
31
+ of a model with an excluded signup field** (#310). v0.35.2 refused such a model in the DDL
32
+ methods, `signup()` and `signin()`, but not in the calls that drop the value: when the access
33
+ was defined by hand or by an earlier deploy and the account signed up through another client,
34
+ `SurrealDBConnectionManager.signup()` or a session opened before the upgrade, an instance
35
+ returned by `authenticate()` or loaded with `get()` wrote the record back without the hash at
36
+ its first `update()` or `upsert()`, with no error: the hash became `NONE` on a `SCHEMALESS`
37
+ table or an optional column, and every later signin failed. These calls are now refused first
38
+ (see Changed), and the stored record stays as it was. README section 19, "User models" and the
39
+ v0.35.2 row of "ORM behaviour: SurrealDB 2.x vs 3.x" describe it; the behaviour is the same on
40
+ both lines.
41
+
8
42
  ## [0.35.3] - 2026-10-23
9
43
 
10
44
  Follow-ups to the review of v0.35.0's full-text search (#304): the warning of `define_indexes()`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: surreal-orm-lite
3
- Version: 0.35.3
3
+ Version: 0.35.4
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
@@ -1337,8 +1337,12 @@ gives such a model the same table, so the two can be called in any order.
1337
1337
  record with what `model_dump()` writes: a field declared `Field(exclude=True)` (`password: str = Field(exclude=True)`)
1338
1338
  would lose its stored value, the password hash, and every later signin would fail. Such a model raises `TypeError`,
1339
1339
  naming the fields, before any request and whatever its schema mode: `access_ddl()`, `define_access()` (with or without
1340
- the table), `table_ddl()`, `define_table()`, `signup()` and `signin()` refuse it. Remove `exclude=True` and leave the
1341
- field out where you serialise the model instead (`model_dump(exclude={"password"})`).
1340
+ the table), `table_ddl()`, `define_table()`, `signup()`, `signin()`, `authenticate()` and `refresh()` refuse it, and so
1341
+ do `update()` and `upsert()` (with or without `tx=`, before any signal), whoever wrote the record — another client, an
1342
+ access defined by hand, a session opened before the upgrade. Remove `exclude=True` and leave the field out where you
1343
+ serialise the model instead (`model_dump(exclude={"password"})`). **Changed in v0.35.4**: `authenticate()`, `refresh()`,
1344
+ `update()` and `upsert()` used to accept such a model, so a record loaded with `authenticate()` or `get()` lost its
1345
+ hash at its first `update()` or `upsert()`.
1342
1346
 
1343
1347
  #### Renewing a session (SurrealDB 3.x only)
1344
1348
 
@@ -5715,12 +5719,15 @@ print(*table, sep="\n")
5715
5719
  - An auth model with a field SIGNUP writes that `Field(exclude=True)` keeps out of `model_dump()`
5716
5720
  (`password: str = Field(exclude=True)`) raises `TypeError` too, naming the fields, before any request and whatever
5717
5721
  its schema mode: `table_ddl()`, `define_table()`, `access_ddl()` and `define_access()` (with or without the table),
5718
- `signup()` and `signin()` refuse it. `update()` and `upsert()` replace the record with what `model_dump()` writes,
5722
+ `signup()`, `signin()`, `authenticate()` and `refresh()` refuse it, and so do `update()` and `upsert()`, with or
5723
+ without `tx=` and before any signal. `update()` and `upsert()` replace the record with what `model_dump()` writes,
5719
5724
  so on any table (`SCHEMALESS`, or defined by hand with `with_table=False`) they would drop the password hash, failing
5720
5725
  every later signin, or be refused by a required column; a `SCHEMAFULL` table would not define the field either, so
5721
5726
  SurrealDB 3.x would refuse every signup and 2.x drop the hash. Remove `exclude=True` and leave the field out where
5722
5727
  you serialise the model instead (`model_dump(exclude={"password"})`). **Changed**: such a model on a `SCHEMALESS`
5723
- table or with `with_table=False` used to be accepted, and its first `update()` or `upsert()` dropped the hash.
5728
+ table or with `with_table=False` used to be accepted, and its first `update()` or `upsert()` dropped the hash; until
5729
+ v0.35.4, `authenticate()`, `refresh()`, `update()` and `upsert()` still accepted it, so a record signed up elsewhere
5730
+ (another client, an access defined by hand) and loaded with `authenticate()` or `get()` lost its hash the same way.
5724
5731
  - Upgrading: a 0.33 `TableType.USER` model's table turns `SCHEMAFULL` at its next `define_access()`; records already
5725
5732
  there are checked at their next write.
5726
5733
 
@@ -6424,7 +6431,7 @@ The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded
6424
6431
  | Two `search()` fields AND-ed | only the records matching every field, each field scored as if searched alone | the same on 3.3; 3.1 can also return records that match only one of the fields, scored `0.0` on the other | v0.35.0 |
6425
6432
  | `search()` on a field without a full-text index | `SurrealDbError` naming the field | the same; 3.1 answers no record | v0.35.0 |
6426
6433
  | `live()` with a `Subquery` that searches a field without a full-text index | `SurrealDbError` naming the field, before the live query starts | the same (the live query would never notify); 3.1 starts it | v0.35.0 |
6427
- | An auth model with a `Field(exclude=True)` field SIGNUP writes (`password: str = Field(exclude=True)`) | `TypeError` before any request, whatever the schema mode and `with_table`: the four DDL methods, `signup()` and `signin()` | same on both lines (a check of the model, no request) | v0.35.2 |
6434
+ | An auth model with a `Field(exclude=True)` field SIGNUP writes (`password: str = Field(exclude=True)`) | `TypeError` before any request, whatever the schema mode and `with_table`: the DDL methods, `signup()`, `signin()`, `authenticate()`, `refresh()`, `update()`, `upsert()` | same on both lines (a check of the model, no request) | v0.35.2 |
6428
6435
  | `define_indexes(tx=)` in a block that writes to the model's table (an ORM write before the index, a write after it) | a write before it: refused (left out of the index); a write after it, to a table holding records, fails the commit with a retryable `SurrealDbConflictError`, again on retry | a write before it: refused (left out of the index, [surrealdb#7618](https://github.com/surrealdb/surrealdb/issues/7618)); a write after it is committed and indexed | v0.35.3 |
6429
6436
  | Full suite and every divergence in this table, re-run on SurrealDB 2.7.0 and 3.3.0 | 2.7.0 identical to 2.6.5 (same passes, same 3.x-only skips) | 3.3.0 identical to 3.2.4, except the system-user signin row | v0.19.1 |
6430
6437
 
@@ -1286,8 +1286,12 @@ gives such a model the same table, so the two can be called in any order.
1286
1286
  record with what `model_dump()` writes: a field declared `Field(exclude=True)` (`password: str = Field(exclude=True)`)
1287
1287
  would lose its stored value, the password hash, and every later signin would fail. Such a model raises `TypeError`,
1288
1288
  naming the fields, before any request and whatever its schema mode: `access_ddl()`, `define_access()` (with or without
1289
- the table), `table_ddl()`, `define_table()`, `signup()` and `signin()` refuse it. Remove `exclude=True` and leave the
1290
- field out where you serialise the model instead (`model_dump(exclude={"password"})`).
1289
+ the table), `table_ddl()`, `define_table()`, `signup()`, `signin()`, `authenticate()` and `refresh()` refuse it, and so
1290
+ do `update()` and `upsert()` (with or without `tx=`, before any signal), whoever wrote the record — another client, an
1291
+ access defined by hand, a session opened before the upgrade. Remove `exclude=True` and leave the field out where you
1292
+ serialise the model instead (`model_dump(exclude={"password"})`). **Changed in v0.35.4**: `authenticate()`, `refresh()`,
1293
+ `update()` and `upsert()` used to accept such a model, so a record loaded with `authenticate()` or `get()` lost its
1294
+ hash at its first `update()` or `upsert()`.
1291
1295
 
1292
1296
  #### Renewing a session (SurrealDB 3.x only)
1293
1297
 
@@ -5664,12 +5668,15 @@ print(*table, sep="\n")
5664
5668
  - An auth model with a field SIGNUP writes that `Field(exclude=True)` keeps out of `model_dump()`
5665
5669
  (`password: str = Field(exclude=True)`) raises `TypeError` too, naming the fields, before any request and whatever
5666
5670
  its schema mode: `table_ddl()`, `define_table()`, `access_ddl()` and `define_access()` (with or without the table),
5667
- `signup()` and `signin()` refuse it. `update()` and `upsert()` replace the record with what `model_dump()` writes,
5671
+ `signup()`, `signin()`, `authenticate()` and `refresh()` refuse it, and so do `update()` and `upsert()`, with or
5672
+ without `tx=` and before any signal. `update()` and `upsert()` replace the record with what `model_dump()` writes,
5668
5673
  so on any table (`SCHEMALESS`, or defined by hand with `with_table=False`) they would drop the password hash, failing
5669
5674
  every later signin, or be refused by a required column; a `SCHEMAFULL` table would not define the field either, so
5670
5675
  SurrealDB 3.x would refuse every signup and 2.x drop the hash. Remove `exclude=True` and leave the field out where
5671
5676
  you serialise the model instead (`model_dump(exclude={"password"})`). **Changed**: such a model on a `SCHEMALESS`
5672
- table or with `with_table=False` used to be accepted, and its first `update()` or `upsert()` dropped the hash.
5677
+ table or with `with_table=False` used to be accepted, and its first `update()` or `upsert()` dropped the hash; until
5678
+ v0.35.4, `authenticate()`, `refresh()`, `update()` and `upsert()` still accepted it, so a record signed up elsewhere
5679
+ (another client, an access defined by hand) and loaded with `authenticate()` or `get()` lost its hash the same way.
5673
5680
  - Upgrading: a 0.33 `TableType.USER` model's table turns `SCHEMAFULL` at its next `define_access()`; records already
5674
5681
  there are checked at their next write.
5675
5682
 
@@ -6373,7 +6380,7 @@ The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded
6373
6380
  | Two `search()` fields AND-ed | only the records matching every field, each field scored as if searched alone | the same on 3.3; 3.1 can also return records that match only one of the fields, scored `0.0` on the other | v0.35.0 |
6374
6381
  | `search()` on a field without a full-text index | `SurrealDbError` naming the field | the same; 3.1 answers no record | v0.35.0 |
6375
6382
  | `live()` with a `Subquery` that searches a field without a full-text index | `SurrealDbError` naming the field, before the live query starts | the same (the live query would never notify); 3.1 starts it | v0.35.0 |
6376
- | An auth model with a `Field(exclude=True)` field SIGNUP writes (`password: str = Field(exclude=True)`) | `TypeError` before any request, whatever the schema mode and `with_table`: the four DDL methods, `signup()` and `signin()` | same on both lines (a check of the model, no request) | v0.35.2 |
6383
+ | An auth model with a `Field(exclude=True)` field SIGNUP writes (`password: str = Field(exclude=True)`) | `TypeError` before any request, whatever the schema mode and `with_table`: the DDL methods, `signup()`, `signin()`, `authenticate()`, `refresh()`, `update()`, `upsert()` | same on both lines (a check of the model, no request) | v0.35.2 |
6377
6384
  | `define_indexes(tx=)` in a block that writes to the model's table (an ORM write before the index, a write after it) | a write before it: refused (left out of the index); a write after it, to a table holding records, fails the commit with a retryable `SurrealDbConflictError`, again on retry | a write before it: refused (left out of the index, [surrealdb#7618](https://github.com/surrealdb/surrealdb/issues/7618)); a write after it is committed and indexed | v0.35.3 |
6378
6385
  | Full suite and every divergence in this table, re-run on SurrealDB 2.7.0 and 3.3.0 | 2.7.0 identical to 2.6.5 (same passes, same 3.x-only skips) | 3.3.0 identical to 3.2.4, except the system-user signin row | v0.19.1 |
6379
6386
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "surreal-orm-lite"
3
- version = "0.35.3"
3
+ version = "0.35.4"
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.35.3"
1
+ __version__ = "0.35.4"
2
2
 
3
3
  from ._sdk import BoundExcluded, BoundIncluded
4
4
  from .aggregations import Aggregation, Avg, Count, Max, Min, Sum
@@ -282,11 +282,14 @@ class AuthenticatedUserMixin:
282
282
 
283
283
  @classmethod
284
284
  def _refuse_signup_fields_excluded(cls) -> None:
285
- """SG1 (#296, #299): refuse a model with a field SIGNUP writes that ``Field(exclude=True)`` keeps out of
285
+ """SG1 (#296, #299, #310): refuse a model with a field SIGNUP writes that ``Field(exclude=True)`` keeps out of
286
286
  ``model_dump()`` (:meth:`_signup_fields_excluded`), whatever its schema mode. Pure:
287
287
  ``BaseSurrealModel._table_ddl()`` (behind ``table_ddl()`` and ``define_table()``), :meth:`access_ddl` (behind
288
- :meth:`define_access`, with or without the table) and :meth:`_auth_variables` (behind :meth:`signup` and
289
- :meth:`signin`) call it before any request.
288
+ :meth:`define_access`, with or without the table), :meth:`_auth_variables` (behind :meth:`signup` and
289
+ :meth:`signin`), :meth:`authenticate`, :meth:`refresh`, and ``update()`` and ``upsert()`` (through
290
+ ``BaseSurrealModel._reject_signup_excluded()``, with or without ``tx``, before any signal) call it before any
291
+ request: whichever call loads the record — ``authenticate()``, a ``get()``, a signup by another client —,
292
+ ``update()`` and ``upsert()`` would drop the stored hash.
290
293
 
291
294
  Raises:
292
295
  TypeError: naming the model and those fields, in declaration order (``schema.signup_excluded_refused()``).
@@ -954,7 +957,9 @@ class AuthenticatedUserMixin:
954
957
  TypeError: the model has a field SIGNUP writes that ``Field(exclude=True)`` keeps
955
958
  out of ``model_dump()`` (see :meth:`access_ddl`) — before any request, so an
956
959
  access defined by hand cannot leave a record that ``update()`` or ``upsert()``
957
- would strip of its password hash.
960
+ would strip of its password hash. :meth:`signin`, :meth:`authenticate`,
961
+ :meth:`refresh`, ``update()`` and ``upsert()`` refuse such a model the same way
962
+ (#310), whoever wrote the record.
958
963
  ValueError: for an unknown field or a missing required one — before any request.
959
964
  SurrealDbAuthenticationError: if the server refuses the signup, or returns no
960
965
  record for the new session (the message says how to grant the permission).
@@ -1004,11 +1009,14 @@ class AuthenticatedUserMixin:
1004
1009
  on the embedded engine too.
1005
1010
 
1006
1011
  Raises:
1012
+ TypeError: as in :meth:`signup` (#310) — before any request: the instance returned
1013
+ would be one ``update()`` and ``upsert()`` strip of its password hash.
1007
1014
  SurrealDbAuthenticationError: if the token is malformed, expired or revoked. A
1008
1015
  malformed one is rejected by the SDK's own schema check without ever reaching
1009
1016
  the server, and is normalised here like any other auth failure.
1010
1017
  SurrealDbError: on the embedded engine without ``bind=True``.
1011
1018
  """
1019
+ cls._refuse_signup_fields_excluded()
1012
1020
  # On a server, bind=True adopts the token on the shared connection once it resolved to an
1013
1021
  # instance; on the embedded engine the exchange runs on the shared session and adopts the
1014
1022
  # token itself — one SDK authenticate(), not a second one through the manager.
@@ -1031,6 +1039,9 @@ class AuthenticatedUserMixin:
1031
1039
  you.
1032
1040
 
1033
1041
  Raises:
1042
+ TypeError: as in :meth:`signup` (#310) — before any request, so the refresh token is
1043
+ not spent: the instance returned would be one ``update()`` and ``upsert()`` strip
1044
+ of its password hash.
1034
1045
  ValueError: if no connection is configured, or the model is not declared with
1035
1046
  ``with_refresh=True`` — both before any request.
1036
1047
  SurrealDbAuthenticationError: if the token is spent or expired, or the server does
@@ -1042,6 +1053,7 @@ class AuthenticatedUserMixin:
1042
1053
  it (:meth:`SurrealDBConnectionManager.get_refresh_token`) and the shared session
1043
1054
  is signed in as that record. The error says which.
1044
1055
  """
1056
+ cls._refuse_signup_fields_excluded()
1045
1057
  manager: type[SurrealDBConnectionManager] = cls._connection_manager() # type: ignore[attr-defined]
1046
1058
  manager.require_connection()
1047
1059
  if not cls._auth_setting("with_refresh", False):
@@ -117,6 +117,7 @@ from .utils import (
117
117
 
118
118
  if TYPE_CHECKING:
119
119
  from .edge import BaseSurrealEdge
120
+ from .model_auth import AuthenticatedUserMixin
120
121
 
121
122
  logger = logging.getLogger(__name__)
122
123
 
@@ -159,6 +160,16 @@ _ANNOTATED: Any = typing.Annotated
159
160
  _PYDANTIC_DIR = os.path.dirname(os.path.abspath(pydantic.__file__))
160
161
 
161
162
 
163
+ @functools.cache
164
+ def _auth_mixin() -> "type[AuthenticatedUserMixin]":
165
+ """``model_auth.AuthenticatedUserMixin``, imported on first use — ``model_auth`` sits above this module — and kept,
166
+ so that the SG1 check of the full replaces ``update()`` and ``upsert()`` (#310) costs a call and an
167
+ ``issubclass()`` on every model."""
168
+ from .model_auth import AuthenticatedUserMixin
169
+
170
+ return AuthenticatedUserMixin
171
+
172
+
162
173
  def _legacy_table_name(cls: type) -> str | None:
163
174
  """Return the deprecated ``_table_name: ClassVar[str]`` of ``cls`` (or a base), else ``None``.
164
175
 
@@ -1462,6 +1473,23 @@ class BaseSurrealModel(BaseModel):
1462
1473
  if cls._is_view():
1463
1474
  raise TypeError(view_write_refused(cls.get_table_name(), f"{cls.__name__}.{call}"))
1464
1475
 
1476
+ @classmethod
1477
+ def _reject_signup_excluded(cls) -> None:
1478
+ """SG1 (#296, #299, #310) on an auth model (``AuthenticatedUserMixin``): refuse it when a field SIGNUP writes is
1479
+ one ``Field(exclude=True)`` keeps out of ``model_dump()`` (``_refuse_signup_fields_excluded()``); nothing on any
1480
+ other model. Pure.
1481
+
1482
+ Called by :meth:`_table_ddl`, after its other refusals, and by the full replaces :meth:`update` and
1483
+ :meth:`upsert`, right after the view and snapshot checks — before any signal, transaction use or request: they
1484
+ write what ``model_dump()`` writes, so they would drop the stored value of such a field (a password hash, and
1485
+ every later signin fails).
1486
+
1487
+ Raises:
1488
+ TypeError: the auth model and those fields, in declaration order (``schema.signup_excluded_refused()``).
1489
+ """
1490
+ if issubclass(cls, _auth_mixin()):
1491
+ cls._refuse_signup_fields_excluded()
1492
+
1465
1493
  @classmethod
1466
1494
  def _require_view(cls, method: str) -> str:
1467
1495
  """The model's view query (:meth:`get_view_query`), or V11 naming *method* (``"view_ddl()"``) (v0.32.0).
@@ -1792,15 +1820,11 @@ class BaseSurrealModel(BaseModel):
1792
1820
  raise TypeError(user_extra_refused(cls.__name__))
1793
1821
  schemafull = clauses.schema_mode == SchemaMode.SCHEMAFULL.value
1794
1822
  fields = [field_statement(table, column, overwrite=overwrite, schemafull=schemafull) for column in cls._table_columns()]
1795
- # Imported here: model_auth sits above this module.
1796
- from .model_auth import AuthenticatedUserMixin
1797
-
1798
- if issubclass(cls, AuthenticatedUserMixin):
1799
- # SG1 (#296, #299), after the other refusals, whatever the schema mode: SIGNUP writes a field model_dump()
1800
- # leaves out, which update() and upsert() would drop and a SCHEMAFULL table would refuse (3.x) or drop
1801
- # (2.x) — checked here, as UX1 is, so that table_ddl() and define_table() refuse the model access_ddl(),
1802
- # define_access(), signup() and signin() refuse.
1803
- cls._refuse_signup_fields_excluded()
1823
+ # SG1 (#296, #299, #310) on an auth model, after the other refusals, whatever the schema mode: SIGNUP writes a
1824
+ # field model_dump() leaves out, which update() and upsert() would drop and a SCHEMAFULL table would refuse
1825
+ # (3.x) or drop (2.x) — checked here, as UX1 is, so that table_ddl() and define_table() refuse the model
1826
+ # access_ddl(), define_access(), signup(), signin(), authenticate(), refresh(), update() and upsert() refuse.
1827
+ cls._reject_signup_excluded()
1804
1828
  return [statement, *fields]
1805
1829
 
1806
1830
  @classmethod
@@ -3382,9 +3406,18 @@ class BaseSurrealModel(BaseModel):
3382
3406
  Emits the same signals as ``save()`` (``pre_save``/``around_save``/``post_save``);
3383
3407
  in a transaction ``around_save`` is skipped and ``post_save`` is deferred to a
3384
3408
  successful commit (consistent with ``save(tx=)``).
3409
+
3410
+ Raises:
3411
+ TypeError: the model is a materialized view (W1); or an auth model
3412
+ (``AuthenticatedUserMixin``) with a field SIGNUP writes that ``Field(exclude=True)``
3413
+ keeps out of ``model_dump()`` (SG1, #310): the replace would drop its stored value
3414
+ (a password hash) — before any signal, transaction use or request, with or
3415
+ without ``tx``.
3416
+ SurrealDbError: the instance is a snapshot read with ``as_of()``.
3385
3417
  """
3386
3418
  self._reject_view_write("upsert()")
3387
3419
  self._reject_snapshot_write("upsert()")
3420
+ self._reject_signup_excluded()
3388
3421
  return await self._save_with_signals(self._do_upsert, tx)
3389
3422
 
3390
3423
  @_cache.invalidates("self")
@@ -3431,9 +3464,18 @@ class BaseSurrealModel(BaseModel):
3431
3464
  Returns:
3432
3465
  The updated row as the SDK reads it (``[]`` for a record that does not exist), or
3433
3466
  ``None`` in a transaction.
3467
+
3468
+ Raises:
3469
+ TypeError: the model is a materialized view (W1); or an auth model
3470
+ (``AuthenticatedUserMixin``) with a field SIGNUP writes that ``Field(exclude=True)``
3471
+ keeps out of ``model_dump()`` (SG1, #310): the replace would drop its stored value
3472
+ (a password hash) — before any signal, transaction use or request, with or
3473
+ without ``tx``.
3474
+ SurrealDbError: the instance is a snapshot read with ``as_of()``, or it has no id.
3434
3475
  """
3435
3476
  self._reject_view_write("update()")
3436
3477
  self._reject_snapshot_write("update()")
3478
+ self._reject_signup_excluded()
3437
3479
  sender = self.__class__
3438
3480
  data = self._write_payload(replace=True)
3439
3481
  record_id = self._record_id()
@@ -88,7 +88,8 @@ refuses ``define_relation()`` of an edge model declared ``SCHEMAFULL`` with data
88
88
  ``user_extra_refused()`` gives the text of UX1, the refusal of a ``SCHEMAFULL`` table the model table DDL checks before
89
89
  any request, and ``signup_excluded_refused()`` that of SG1, an auth model with a field SIGNUP writes that
90
90
  ``Field(exclude=True)`` keeps out of ``model_dump()``, refused whatever its schema mode by the model table DDL, the
91
- access DDL, ``signup()`` and ``signin()`` (#299).
91
+ access DDL, ``signup()`` and ``signin()`` (#299), ``authenticate()``, ``refresh()``, ``update()`` and ``upsert()``
92
+ (#310).
92
93
 
93
94
  The module sits low in the package: it imports neither ``model_base`` nor ``connection_manager``, so both can import
94
95
  it.
@@ -1955,8 +1956,9 @@ def signup_excluded_refused(model: str, fields: Sequence[str]) -> str:
1955
1956
  ``Field(exclude=True)`` keeps out of ``model_dump()`` (SG1): ``update()`` and ``upsert()`` replace the stored record
1956
1957
  with what ``model_dump()`` writes, whatever the table's schema mode, so they drop them or a required column refuses
1957
1958
  them (#299), and a ``SCHEMAFULL`` table defined from the model has no column for them (#296). ``table_ddl()``,
1958
- ``define_table()``, ``access_ddl()``, ``define_access()``, ``signup()`` and ``signin()`` raise it before any
1959
- request. Pure."""
1959
+ ``define_table()``, ``access_ddl()``, ``define_access()``, ``signup()``, ``signin()``, ``authenticate()``,
1960
+ ``refresh()``, ``update()`` and ``upsert()`` raise it before any request — ``update()`` and ``upsert()`` before any
1961
+ signal too, with or without ``tx`` (#310), whoever wrote the record they replace. Pure."""
1960
1962
  names = ", ".join(repr(name) for name in fields)
1961
1963
  pronoun = "it" if len(fields) == 1 else "them"
1962
1964
  return (
@@ -1966,5 +1968,5 @@ def signup_excluded_refused(model: str, fields: Sequence[str]) -> str:
1966
1968
  f"SCHEMAFULL table defined from the model has no column for {pronoun} either (SurrealDB 3.x refuses the signup, "
1967
1969
  f"2.x drops {pronoun}). Remove exclude=True and leave {pronoun} out where you serialise the model instead "
1968
1970
  f"(model_dump(exclude={{{names}}})); until then table_ddl(), define_table(), access_ddl(), define_access(), "
1969
- f"signup() and signin() refuse {model}."
1971
+ f"signup(), signin(), authenticate(), refresh(), update() and upsert() refuse {model}."
1970
1972
  )