surreal-orm-lite 0.37.0__tar.gz → 0.37.2__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.
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/CHANGELOG.md +98 -1
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/PKG-INFO +27 -12
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/README.md +26 -11
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/pyproject.toml +1 -1
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/__init__.py +1 -1
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/define_parser.py +4 -2
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/model_auth.py +33 -12
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/model_base.py +106 -11
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/query_set.py +3 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/schema_state.py +3 -2
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/search.py +2 -1
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/utils.py +22 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/vector.py +28 -19
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/.gitignore +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/LICENSE +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/Makefile +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/_sdk.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/aggregations.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/auth.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/cache.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/changefeed.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/concurrency.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/connection_config.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/connection_manager.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/constants.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/decoding.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/edge.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/embedded.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/encoding.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/enum.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/exceptions.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/functions.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/geo.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/hybrid.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/introspection.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/live.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/model_ddl.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/model_generator.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/py.typed +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/q.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/routing.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/schema.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/signals.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/subquery.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/surql_literal.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/__init__.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/database.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/fixtures.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/time_travel.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/transaction.py +0 -0
- {surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/types.py +0 -0
|
@@ -5,6 +5,102 @@ 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.37.2] - 2026-10-27
|
|
9
|
+
|
|
10
|
+
A model with a `primary_key` can have its access defined on SurrealDB 3.x. No new public API.
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`access_ddl()` and `define_access()` work for a model with a `primary_key` on SurrealDB 3.x** (#338).
|
|
15
|
+
The SIGNUP clause built the record id with `type::thing('<table>', $<key>)`, which 3.x refuses at
|
|
16
|
+
`DEFINE`, so `define_access()` failed there; `type::record(table, key)` is no replacement, since 2.x
|
|
17
|
+
reads it as a type check that fails every signup. SIGNUP now sets the id from the bound key,
|
|
18
|
+
`CREATE <table> SET id = $<key>, ...`, a statement accepted by 3.x, 2.x and the embedded engine
|
|
19
|
+
that gives the record id `<table>:<key>` on all of them. `access_ddl()` stays pure, with no
|
|
20
|
+
version parameter, and a model without a `primary_key` is unchanged.
|
|
21
|
+
- **A signup leaving the `primary_key` as `None` is refused before the exchange.** `SET id = NONE`
|
|
22
|
+
would have the server mint a random record id, one no `objects().get(<key>)` addresses; the
|
|
23
|
+
`ValueError` names the key.
|
|
24
|
+
- **`parse_define_access()` reads the new form**: the `id = $<key>` item is one of `signup_fields`.
|
|
25
|
+
The older `type::thing(...)` and `type::record(...)` targets are still read.
|
|
26
|
+
|
|
27
|
+
### Notes
|
|
28
|
+
|
|
29
|
+
- **Upgrading**: re-run `define_access()` for such a model to replace the old SIGNUP clause. Accesses
|
|
30
|
+
already defined on 2.x keep working; on 2.x the old clause and the new one create the same records.
|
|
31
|
+
|
|
32
|
+
## [0.37.1] - 2026-10-24
|
|
33
|
+
|
|
34
|
+
Follow-ups to the review of v0.36.3 (#327): a `Literal[None]` member of a vector field's union
|
|
35
|
+
reads as `None`, and a vector field declared through a forward reference gets the vector checks
|
|
36
|
+
of the `class` statement once its name resolves. Any model a forward reference left incomplete is
|
|
37
|
+
completed before the ORM writes its DDL or builds a queryset. No new public API.
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
|
|
41
|
+
- **`VectorField[d] | Literal[None]` is read as a vector field** (#327). Since v0.36.3 a
|
|
42
|
+
`Literal[None]` union member counted as a type other than `None`: `get_vector_info()` and
|
|
43
|
+
`is_vector_field()` raised `ValueError` for that annotation and the `class` statement refused
|
|
44
|
+
the field, although `Literal[None]` admits only `None` and `define_table()` already read it as
|
|
45
|
+
`None`. Such a member now counts as `None`: the annotation gives `(d, 'F32')` wherever
|
|
46
|
+
`VectorField[d] | None` does (`get_vector_info()`, `is_vector_field()`, the `class`-statement
|
|
47
|
+
checks of a vector index, `similar_to()`, and `define_table()` with
|
|
48
|
+
`option<array<float, d>>`). A `Literal` holding another value (`Literal[None, "x"]`) next to a
|
|
49
|
+
marker is still refused.
|
|
50
|
+
- **A vector field declared through a forward reference is checked once its name resolves**
|
|
51
|
+
(#327). A field annotated with a name defined after the class (`e: "Later" = None`, then
|
|
52
|
+
`Later = VectorField[3]`) has no `Vector` marker at the `class` statement, so since v0.36.0 the
|
|
53
|
+
vector checks skipped it: a vector index of another dimension or storage type, or an ambiguous
|
|
54
|
+
annotation such as `Later = VectorField[3] | str`, was accepted once `model_rebuild()` or the
|
|
55
|
+
model's first use resolved the name. Until then, `table_ddl()` and `define_table()` wrote the
|
|
56
|
+
column as `any`, `define_indexes()` defined the index unchecked and `similar_to()` accepted a
|
|
57
|
+
query vector of any length, without an error. The checks now run again when Pydantic completes
|
|
58
|
+
the model (at `model_rebuild()`, or at its first instantiation, validation or JSON schema), and
|
|
59
|
+
the ORM completes such a model before `table_ddl()`, `define_table()`, `index_ddl()`,
|
|
60
|
+
`define_indexes()`, `get_indexes()` or a queryset (`similar_to()` included) reads it, resolving
|
|
61
|
+
the name as Pydantic's first instantiation does: with the local names of the caller, then the
|
|
62
|
+
names of the model's module (a caller's local name wins, and the field keeps what it resolved
|
|
63
|
+
to). The refusals are those of the field written directly, naming the model, the index and
|
|
64
|
+
the field, raised before anything is sent; a refused model stays incomplete, so each of these
|
|
65
|
+
calls raises the same error again. A matching index is accepted, and `similar_to()` checks the
|
|
66
|
+
query vector against the field's dimension. A name still undefined leaves the model incomplete
|
|
67
|
+
and read as before. A model complete at its `class` statement is checked there only, in the same
|
|
68
|
+
order and with the same messages.
|
|
69
|
+
- **Every model a forward reference left incomplete is completed before the ORM reads it**
|
|
70
|
+
(#327). The completion of the previous bullet applies to any model Pydantic could not complete
|
|
71
|
+
at its `class` statement, with or without a vector field: `table_ddl()`, `define_table()`,
|
|
72
|
+
`index_ddl()`, `define_indexes()`, `get_indexes()` and every queryset complete it first. Until
|
|
73
|
+
now such a model was read with its unresolved fields as `any` until `model_rebuild()` or its
|
|
74
|
+
first instance: in `Author` with `best: "Book | None" = None` and `score: "Score" = 0`, `Book`
|
|
75
|
+
and `Score = int` defined after it, `table_ddl()` and `define_table()` wrote `best TYPE any`
|
|
76
|
+
and `score TYPE any DEFAULT 0`, and the cross-connection check of a queryset that follows a
|
|
77
|
+
link (`fetch()`) saw no linked model in such a field. Its columns now get the resolved kinds,
|
|
78
|
+
whether or not the model was instantiated first — what these calls already wrote after an
|
|
79
|
+
instance: `best TYPE option<object> FLEXIBLE` and `score TYPE int DEFAULT 0` on a `SCHEMAFULL`
|
|
80
|
+
table —, and its links are resolved for the cross-connection check, without `model_rebuild()`.
|
|
81
|
+
**Upgrading**: `define_table()` on such a model now redefines a column it wrote `any` with its
|
|
82
|
+
kind, and SurrealDB checks the values written to that column against it from then on. A name
|
|
83
|
+
still undefined leaves the model read as before.
|
|
84
|
+
|
|
85
|
+
### Notes
|
|
86
|
+
|
|
87
|
+
- **CHANGELOG correction**: the `### Changed` bullet of `## [0.36.3]` said that every spelling
|
|
88
|
+
v0.36.2 read as a vector field gives the same result. A field with two different `Vector`
|
|
89
|
+
markers, which v0.36.2 read by its first marker, is refused since v0.36.3: the sentence now
|
|
90
|
+
reads "Every spelling with a single `Vector` marker that v0.36.2 read as a vector field gives
|
|
91
|
+
the same result."
|
|
92
|
+
- **Docs**: README section 37 (Vector search) says that `get_vector_info()` and
|
|
93
|
+
`is_vector_field()` raise `ValueError` for a field or annotation with no single dimension (code
|
|
94
|
+
that scans the fields of a plain Pydantic model has no `class`-statement check, so it gets the
|
|
95
|
+
exception where v0.36.2 returned `False`), that a `Literal[None]` member counts as `None`, and
|
|
96
|
+
which calls check a field declared through a forward reference. Section 35 (Model table DDL)
|
|
97
|
+
says that such a field gets the kind of the type its name resolves to, before or after an
|
|
98
|
+
instance.
|
|
99
|
+
- The fixes are in the ORM's model checks, built on Pydantic's `__pydantic_on_complete__` hook
|
|
100
|
+
(available in the supported `pydantic>=2.13.4`): the behaviour is the same on SurrealDB 2.x and
|
|
101
|
+
3.x and on the embedded engine. Server pins unchanged: tested against SurrealDB 3.3.4 and 2.7.0,
|
|
102
|
+
plus 3.1.5 for backward compatibility.
|
|
103
|
+
|
|
8
104
|
## [0.37.0] - 2026-10-24
|
|
9
105
|
|
|
10
106
|
Hybrid search: a queryset fuses the records nearest to a query vector, as `similar_to()` finds
|
|
@@ -212,7 +308,8 @@ Follow-up to the review of v0.36.0 (#316): a vector field declared with `| None`
|
|
|
212
308
|
whether or not it declares indexes. Until v0.36.2 such a model was accepted (the first of two
|
|
213
309
|
markers decided the checks, a union with another type was not a vector field).
|
|
214
310
|
`get_vector_info()` and `is_vector_field()` raise the same `ValueError` for such a field or
|
|
215
|
-
annotation. Every spelling that v0.36.2 read as a vector field
|
|
311
|
+
annotation. Every spelling with a single `Vector` marker that v0.36.2 read as a vector field
|
|
312
|
+
gives the same result.
|
|
216
313
|
|
|
217
314
|
### Notes
|
|
218
315
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: surreal-orm-lite
|
|
3
|
-
Version: 0.37.
|
|
3
|
+
Version: 0.37.2
|
|
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
|
|
@@ -1297,7 +1297,9 @@ a concurrent server).
|
|
|
1297
1297
|
|
|
1298
1298
|
The model must declare either an `id` field or a `primary_key`, as every ORM model must. Prefer
|
|
1299
1299
|
`id` here so the server mints the record id during SIGNUP; configure `primary_key` when identity
|
|
1300
|
-
_is_ a column, and the SIGNUP clause
|
|
1300
|
+
_is_ a column, and the SIGNUP clause sets the record id from it to match
|
|
1301
|
+
(`CREATE User SET id = $email, email = $email, …`): the same statement on SurrealDB 2.x, 3.x and the embedded engine,
|
|
1302
|
+
and the record id is the key on all of them.
|
|
1301
1303
|
|
|
1302
1304
|
#### Configuration
|
|
1303
1305
|
|
|
@@ -4505,10 +4507,11 @@ reads, stores, logs or writes them.
|
|
|
4505
4507
|
for a field without `TYPE`, as in the full ORM.
|
|
4506
4508
|
- **Accesses are database-level**: they are in `schema.accesses`, and `TableState` has no `access` attribute; find
|
|
4507
4509
|
a table's with `[a for a in schema.accesses.values() if a.table == "user"]`. `table`, `signup_fields` and
|
|
4508
|
-
`signin_where` are read from `SIGNUP (CREATE <table> SET …)` (
|
|
4509
|
-
`CREATE type::
|
|
4510
|
-
`SIGNIN (SELECT … FROM <table> WHERE …)`. The full ORM reads the
|
|
4511
|
-
empty, with field names unescaped; durations are kept as rendered,
|
|
4510
|
+
`signin_where` are read from `SIGNUP (CREATE <table> SET …)` (the form `define_access()` uses, whose
|
|
4511
|
+
`id = $<key>` for a `primary_key` is one of the `signup_fields`; also `CREATE type::thing('<table>', …) SET …` and
|
|
4512
|
+
`CREATE type::record('<table>', …) SET …`) and `SIGNIN (SELECT … FROM <table> WHERE …)`. The full ORM reads the
|
|
4513
|
+
first form only, and another shape leaves them empty, with field names unescaped; durations are kept as rendered,
|
|
4514
|
+
`'NONE'` included.
|
|
4512
4515
|
- **`encrypted` is not provided**: the lite has no `Encrypted` type, so a hashing `VALUE`
|
|
4513
4516
|
(`crypto::argon2::generate($value)`) stays in `FieldState.value` and the field is generated as a writable field.
|
|
4514
4517
|
- **APIs and the GraphQL config are not typed**: their definitions are in `SchemaState.other["apis"]` and
|
|
@@ -5508,6 +5511,12 @@ Each column's `TYPE` comes from its annotation (`Annotated` unwrapped):
|
|
|
5508
5511
|
|
|
5509
5512
|
Anything else is `any`.
|
|
5510
5513
|
|
|
5514
|
+
A field annotated with a name defined after the class (a forward reference: `score: "Score" = 0`, then `Score = int`)
|
|
5515
|
+
gets the kind of the type its name resolves to. Since v0.37.1, `table_ddl()` and `define_table()` complete such a model
|
|
5516
|
+
first, as its first instantiation does, so they write the same statements before and after an instance (`score` is
|
|
5517
|
+
`TYPE int DEFAULT 0`, which earlier versions wrote `TYPE any DEFAULT 0` until the model was instantiated or rebuilt). A
|
|
5518
|
+
name still undefined gives `any`.
|
|
5519
|
+
|
|
5511
5520
|
- **Columns**: every field but `id` (and an edge's `in_` and `out`), under its column — its alias, if any
|
|
5512
5521
|
([section 20](#20-field-aliases-server_fields-and-mergerefreshfalse)) —, then the Pydantic `@computed_field`s; a
|
|
5513
5522
|
`Field(exclude=True)` field is left out. A sub-model's fields follow its column (`address.city`, `subs.*.city`), its
|
|
@@ -6225,7 +6234,11 @@ the default —, `I64`, `I32` or `I16`). An `Index` with `hnsw=True` is a vector
|
|
|
6225
6234
|
`SurrealConfigDict(indexes=[...])` next to the full-text indexes of
|
|
6226
6235
|
[section 36](#36-full-text-search-search-searchscore-searchhighlight-analyzer-index). Its attributes hold what was
|
|
6227
6236
|
declared (`None` for an option not given). When the class is defined, two vector indexes on one column are refused,
|
|
6228
|
-
and so is a vector index whose dimension or storage type differs from its field's `VectorField`.
|
|
6237
|
+
and so is a vector index whose dimension or storage type differs from its field's `VectorField`. A field annotated
|
|
6238
|
+
with a name defined after the class (a forward reference) is checked once the name resolves, with the same error: at
|
|
6239
|
+
`model_rebuild()`, at the model's first instantiation, validation or JSON schema, and before `table_ddl()`,
|
|
6240
|
+
`define_table()`, `index_ddl()`, `define_indexes()`, `get_indexes()` or a queryset (`similar_to()` included) reads the
|
|
6241
|
+
model. Once refused, each of these raises it again.
|
|
6229
6242
|
|
|
6230
6243
|
```python
|
|
6231
6244
|
from surreal_orm_lite import (
|
|
@@ -6337,10 +6350,11 @@ print(get_vector_info(Document.model_fields["embedding"]), is_vector_field(Passa
|
|
|
6337
6350
|
`VectorField[d]` is already optional, so it needs no `| None`. Written `VectorField[d] | None` or
|
|
6338
6351
|
`Optional[VectorField[d]]`, its `None` default sits inside a union member, where Pydantic ignores it with an
|
|
6339
6352
|
`UnsupportedFieldAttributeWarning`: write `= None`, or the field is required. The ORM reads these spellings, and
|
|
6340
|
-
`Annotated[list[float], Vector(d)] | None`, like the plain ones
|
|
6341
|
-
when the class is defined, the same dimension for `similar_to()`, the same
|
|
6342
|
-
that holds a vector next to a type other than `None`, or two different
|
|
6343
|
-
class statement refuses it, naming the field
|
|
6353
|
+
`Annotated[list[float], Vector(d)] | None`, like the plain ones (a `Literal[None]` member counts as `None`): the same
|
|
6354
|
+
column, the same checks of the vector index when the class is defined, the same dimension for `similar_to()`, the same
|
|
6355
|
+
answer from `get_vector_info()`. A union that holds a vector next to a type other than `None`, or two different
|
|
6356
|
+
`Vector` markers, has no single dimension: the class statement refuses it, naming the field, and `get_vector_info()`
|
|
6357
|
+
and `is_vector_field()` raise `ValueError` for such a field or annotation.
|
|
6344
6358
|
|
|
6345
6359
|
#### Find the nearest
|
|
6346
6360
|
|
|
@@ -6810,7 +6824,7 @@ features introduced in SurrealDB 3.x. On 2.x the ORM degrades gracefully. Capabi
|
|
|
6810
6824
|
listed behave the same on both lines. The 2.x column was measured on 2.6.5 and holds unchanged
|
|
6811
6825
|
on 2.7.0. The 3.x column was measured on 3.2.4 and holds on 3.3.0, except where a row says
|
|
6812
6826
|
otherwise. The full suite and every divergence below were re-verified on both new versions.
|
|
6813
|
-
Rows added in v0.20.0 were measured directly on 2.7.0 and 3.3.0; rows added in v0.21.0 on 2.7.0 and 3.3.2, re-verified on 3.3.3, with 3.1.5 where it differs; rows added in v0.22.0 on 2.7.0 and 3.3.3, with 3.1.5 where it differs; rows added in v0.23.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.24.0 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.26.0 on 2.7.0 and 3.3.4, in memory and on versioned storage, identical on 3.1.5; rows added in v0.27.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.28.0 on 2.7.0 and 3.3.4, identical on 3.1.5; the rows added in v0.28.1 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.29.0 on 2.7.0 and 3.3.4 in one process, identical on 3.1.5. The row added in v0.29.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.30.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.30.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. The row added in v0.30.7 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5: its parser refuses a statement that nests six objects, and `update()` nests at most four. Rows added in v0.31.0 were measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. The row added in v0.31.1 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.32.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 but accepts raw writes to a view. Rows added in v0.33.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4. Rows added in v0.34.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 except that it refuses a Python `set` written to a `set` field, and an object item of an optional untyped `list`. Rows added in v0.35.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.35.2 was measured on 2.7.0 and 3.3.4, identical on 3.1.5. The row added in v0.35.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.36.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.36.2 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.37.0 were measured on 2.7.0, 3.3.4, 3.2.6 and the embedded engine, with 3.1.5 and 3.2.6 where they differ from 3.3.4.
|
|
6827
|
+
Rows added in v0.20.0 were measured directly on 2.7.0 and 3.3.0; rows added in v0.21.0 on 2.7.0 and 3.3.2, re-verified on 3.3.3, with 3.1.5 where it differs; rows added in v0.22.0 on 2.7.0 and 3.3.3, with 3.1.5 where it differs; rows added in v0.23.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.24.0 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.26.0 on 2.7.0 and 3.3.4, in memory and on versioned storage, identical on 3.1.5; rows added in v0.27.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.28.0 on 2.7.0 and 3.3.4, identical on 3.1.5; the rows added in v0.28.1 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.29.0 on 2.7.0 and 3.3.4 in one process, identical on 3.1.5. The row added in v0.29.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.30.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.30.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. The row added in v0.30.7 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5: its parser refuses a statement that nests six objects, and `update()` nests at most four. Rows added in v0.31.0 were measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. The row added in v0.31.1 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.32.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 but accepts raw writes to a view. Rows added in v0.33.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4. Rows added in v0.34.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 except that it refuses a Python `set` written to a `set` field, and an object item of an optional untyped `list`. Rows added in v0.35.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.35.2 was measured on 2.7.0 and 3.3.4, identical on 3.1.5. The row added in v0.35.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.36.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.36.2 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.37.0 were measured on 2.7.0, 3.3.4, 3.2.6 and the embedded engine, with 3.1.5 and 3.2.6 where they differ from 3.3.4. The row added in v0.37.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5.
|
|
6814
6828
|
The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded engine](#orm-behaviour-the-embedded-engine).
|
|
6815
6829
|
|
|
6816
6830
|
| ORM capability | SurrealDB 2.6.x / 2.7.x | SurrealDB 3.2.x / 3.3.x | Since |
|
|
@@ -6855,6 +6869,7 @@ The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded
|
|
|
6855
6869
|
| Signing in as a system user while a record session is open | permissions change, `$auth` still points at the record — only `invalidate()` clears it | 3.2.x: same as 2.x. **3.3.0**: the identity is cleared and `info()` returns `None`; `invalidate()` stays the portable log-out | v0.16.0 |
|
|
6856
6870
|
| Duplicate signin identifier in the record table | signin fails (`No record was returned`) | signin succeeds, picking one record | v0.16.0 |
|
|
6857
6871
|
| Model auth (`signup`/`signin`/`authenticate`, `access_ddl`/`define_access`) | same on both lines (verified on 2.6.5) | same on both lines (verified on 3.2.4) | v0.17.0 |
|
|
6872
|
+
| Model auth with a `primary_key` (`access_ddl()`, `define_access()`) | same on both lines: SIGNUP runs `CREATE <table> SET id = $<key>, …`, so the record id is the key (verified on 2.7.0) | same on both lines (verified on 3.3.4 and 3.1.5); v0.17.0 to v0.37.1 rendered `type::thing`, which 3.x refuses, so `define_access()` failed | v0.37.2 |
|
|
6858
6873
|
| Model auth session isolation (each call on its own ephemeral connection) | same on both lines (an SDK/connection property, not a server one) | same on both lines (verified on 3.2.4) | v0.17.0 |
|
|
6859
6874
|
| Hydrated instance's password field after `signup`/`signin` | holds the stored **hash**, never the plaintext | same on both lines | v0.17.0 |
|
|
6860
6875
|
| Model config `with_refresh=True` → `define_access()` | raises `SurrealDbError` (clause does not parse; message names the 3.x requirement) | applies, and `AuthResult.tokens.refresh` is populated | v0.17.0 |
|
|
@@ -1246,7 +1246,9 @@ a concurrent server).
|
|
|
1246
1246
|
|
|
1247
1247
|
The model must declare either an `id` field or a `primary_key`, as every ORM model must. Prefer
|
|
1248
1248
|
`id` here so the server mints the record id during SIGNUP; configure `primary_key` when identity
|
|
1249
|
-
_is_ a column, and the SIGNUP clause
|
|
1249
|
+
_is_ a column, and the SIGNUP clause sets the record id from it to match
|
|
1250
|
+
(`CREATE User SET id = $email, email = $email, …`): the same statement on SurrealDB 2.x, 3.x and the embedded engine,
|
|
1251
|
+
and the record id is the key on all of them.
|
|
1250
1252
|
|
|
1251
1253
|
#### Configuration
|
|
1252
1254
|
|
|
@@ -4454,10 +4456,11 @@ reads, stores, logs or writes them.
|
|
|
4454
4456
|
for a field without `TYPE`, as in the full ORM.
|
|
4455
4457
|
- **Accesses are database-level**: they are in `schema.accesses`, and `TableState` has no `access` attribute; find
|
|
4456
4458
|
a table's with `[a for a in schema.accesses.values() if a.table == "user"]`. `table`, `signup_fields` and
|
|
4457
|
-
`signin_where` are read from `SIGNUP (CREATE <table> SET …)` (
|
|
4458
|
-
`CREATE type::
|
|
4459
|
-
`SIGNIN (SELECT … FROM <table> WHERE …)`. The full ORM reads the
|
|
4460
|
-
empty, with field names unescaped; durations are kept as rendered,
|
|
4459
|
+
`signin_where` are read from `SIGNUP (CREATE <table> SET …)` (the form `define_access()` uses, whose
|
|
4460
|
+
`id = $<key>` for a `primary_key` is one of the `signup_fields`; also `CREATE type::thing('<table>', …) SET …` and
|
|
4461
|
+
`CREATE type::record('<table>', …) SET …`) and `SIGNIN (SELECT … FROM <table> WHERE …)`. The full ORM reads the
|
|
4462
|
+
first form only, and another shape leaves them empty, with field names unescaped; durations are kept as rendered,
|
|
4463
|
+
`'NONE'` included.
|
|
4461
4464
|
- **`encrypted` is not provided**: the lite has no `Encrypted` type, so a hashing `VALUE`
|
|
4462
4465
|
(`crypto::argon2::generate($value)`) stays in `FieldState.value` and the field is generated as a writable field.
|
|
4463
4466
|
- **APIs and the GraphQL config are not typed**: their definitions are in `SchemaState.other["apis"]` and
|
|
@@ -5457,6 +5460,12 @@ Each column's `TYPE` comes from its annotation (`Annotated` unwrapped):
|
|
|
5457
5460
|
|
|
5458
5461
|
Anything else is `any`.
|
|
5459
5462
|
|
|
5463
|
+
A field annotated with a name defined after the class (a forward reference: `score: "Score" = 0`, then `Score = int`)
|
|
5464
|
+
gets the kind of the type its name resolves to. Since v0.37.1, `table_ddl()` and `define_table()` complete such a model
|
|
5465
|
+
first, as its first instantiation does, so they write the same statements before and after an instance (`score` is
|
|
5466
|
+
`TYPE int DEFAULT 0`, which earlier versions wrote `TYPE any DEFAULT 0` until the model was instantiated or rebuilt). A
|
|
5467
|
+
name still undefined gives `any`.
|
|
5468
|
+
|
|
5460
5469
|
- **Columns**: every field but `id` (and an edge's `in_` and `out`), under its column — its alias, if any
|
|
5461
5470
|
([section 20](#20-field-aliases-server_fields-and-mergerefreshfalse)) —, then the Pydantic `@computed_field`s; a
|
|
5462
5471
|
`Field(exclude=True)` field is left out. A sub-model's fields follow its column (`address.city`, `subs.*.city`), its
|
|
@@ -6174,7 +6183,11 @@ the default —, `I64`, `I32` or `I16`). An `Index` with `hnsw=True` is a vector
|
|
|
6174
6183
|
`SurrealConfigDict(indexes=[...])` next to the full-text indexes of
|
|
6175
6184
|
[section 36](#36-full-text-search-search-searchscore-searchhighlight-analyzer-index). Its attributes hold what was
|
|
6176
6185
|
declared (`None` for an option not given). When the class is defined, two vector indexes on one column are refused,
|
|
6177
|
-
and so is a vector index whose dimension or storage type differs from its field's `VectorField`.
|
|
6186
|
+
and so is a vector index whose dimension or storage type differs from its field's `VectorField`. A field annotated
|
|
6187
|
+
with a name defined after the class (a forward reference) is checked once the name resolves, with the same error: at
|
|
6188
|
+
`model_rebuild()`, at the model's first instantiation, validation or JSON schema, and before `table_ddl()`,
|
|
6189
|
+
`define_table()`, `index_ddl()`, `define_indexes()`, `get_indexes()` or a queryset (`similar_to()` included) reads the
|
|
6190
|
+
model. Once refused, each of these raises it again.
|
|
6178
6191
|
|
|
6179
6192
|
```python
|
|
6180
6193
|
from surreal_orm_lite import (
|
|
@@ -6286,10 +6299,11 @@ print(get_vector_info(Document.model_fields["embedding"]), is_vector_field(Passa
|
|
|
6286
6299
|
`VectorField[d]` is already optional, so it needs no `| None`. Written `VectorField[d] | None` or
|
|
6287
6300
|
`Optional[VectorField[d]]`, its `None` default sits inside a union member, where Pydantic ignores it with an
|
|
6288
6301
|
`UnsupportedFieldAttributeWarning`: write `= None`, or the field is required. The ORM reads these spellings, and
|
|
6289
|
-
`Annotated[list[float], Vector(d)] | None`, like the plain ones
|
|
6290
|
-
when the class is defined, the same dimension for `similar_to()`, the same
|
|
6291
|
-
that holds a vector next to a type other than `None`, or two different
|
|
6292
|
-
class statement refuses it, naming the field
|
|
6302
|
+
`Annotated[list[float], Vector(d)] | None`, like the plain ones (a `Literal[None]` member counts as `None`): the same
|
|
6303
|
+
column, the same checks of the vector index when the class is defined, the same dimension for `similar_to()`, the same
|
|
6304
|
+
answer from `get_vector_info()`. A union that holds a vector next to a type other than `None`, or two different
|
|
6305
|
+
`Vector` markers, has no single dimension: the class statement refuses it, naming the field, and `get_vector_info()`
|
|
6306
|
+
and `is_vector_field()` raise `ValueError` for such a field or annotation.
|
|
6293
6307
|
|
|
6294
6308
|
#### Find the nearest
|
|
6295
6309
|
|
|
@@ -6759,7 +6773,7 @@ features introduced in SurrealDB 3.x. On 2.x the ORM degrades gracefully. Capabi
|
|
|
6759
6773
|
listed behave the same on both lines. The 2.x column was measured on 2.6.5 and holds unchanged
|
|
6760
6774
|
on 2.7.0. The 3.x column was measured on 3.2.4 and holds on 3.3.0, except where a row says
|
|
6761
6775
|
otherwise. The full suite and every divergence below were re-verified on both new versions.
|
|
6762
|
-
Rows added in v0.20.0 were measured directly on 2.7.0 and 3.3.0; rows added in v0.21.0 on 2.7.0 and 3.3.2, re-verified on 3.3.3, with 3.1.5 where it differs; rows added in v0.22.0 on 2.7.0 and 3.3.3, with 3.1.5 where it differs; rows added in v0.23.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.24.0 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.26.0 on 2.7.0 and 3.3.4, in memory and on versioned storage, identical on 3.1.5; rows added in v0.27.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.28.0 on 2.7.0 and 3.3.4, identical on 3.1.5; the rows added in v0.28.1 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.29.0 on 2.7.0 and 3.3.4 in one process, identical on 3.1.5. The row added in v0.29.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.30.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.30.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. The row added in v0.30.7 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5: its parser refuses a statement that nests six objects, and `update()` nests at most four. Rows added in v0.31.0 were measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. The row added in v0.31.1 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.32.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 but accepts raw writes to a view. Rows added in v0.33.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4. Rows added in v0.34.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 except that it refuses a Python `set` written to a `set` field, and an object item of an optional untyped `list`. Rows added in v0.35.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.35.2 was measured on 2.7.0 and 3.3.4, identical on 3.1.5. The row added in v0.35.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.36.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.36.2 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.37.0 were measured on 2.7.0, 3.3.4, 3.2.6 and the embedded engine, with 3.1.5 and 3.2.6 where they differ from 3.3.4.
|
|
6776
|
+
Rows added in v0.20.0 were measured directly on 2.7.0 and 3.3.0; rows added in v0.21.0 on 2.7.0 and 3.3.2, re-verified on 3.3.3, with 3.1.5 where it differs; rows added in v0.22.0 on 2.7.0 and 3.3.3, with 3.1.5 where it differs; rows added in v0.23.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.24.0 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.26.0 on 2.7.0 and 3.3.4, in memory and on versioned storage, identical on 3.1.5; rows added in v0.27.0 on 2.7.0 and 3.3.4, with 3.1.5 where it differs; rows added in v0.28.0 on 2.7.0 and 3.3.4, identical on 3.1.5; the rows added in v0.28.1 on 2.7.0 and 3.3.4, identical on 3.1.5; rows added in v0.29.0 on 2.7.0 and 3.3.4 in one process, identical on 3.1.5. The row added in v0.29.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.30.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.30.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. The row added in v0.30.7 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5: its parser refuses a statement that nests six objects, and `update()` nests at most four. Rows added in v0.31.0 were measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. The row added in v0.31.1 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5. Rows added in v0.32.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 but accepts raw writes to a view. Rows added in v0.33.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4. Rows added in v0.34.0 were measured on 2.7.0, 3.3.4 and the embedded engine; 3.1.5 behaves as 3.3.4 except that it refuses a Python `set` written to a `set` field, and an object item of an optional untyped `list`. Rows added in v0.35.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.35.2 was measured on 2.7.0 and 3.3.4, identical on 3.1.5. The row added in v0.35.3 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.36.0 were measured on 2.7.0, 3.3.4 and the embedded engine, with 3.1.5 where it differs. The row added in v0.36.2 was measured on 2.7.0 and 3.3.4, over WebSocket and HTTP, and on the embedded engine, identical on 3.1.5. Rows added in v0.37.0 were measured on 2.7.0, 3.3.4, 3.2.6 and the embedded engine, with 3.1.5 and 3.2.6 where they differ from 3.3.4. The row added in v0.37.2 was measured on 2.7.0, 3.3.4 and the embedded engine, identical on 3.1.5.
|
|
6763
6777
|
The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded engine](#orm-behaviour-the-embedded-engine).
|
|
6764
6778
|
|
|
6765
6779
|
| ORM capability | SurrealDB 2.6.x / 2.7.x | SurrealDB 3.2.x / 3.3.x | Since |
|
|
@@ -6804,6 +6818,7 @@ The SDK's in-process engine has a table of its own: [ORM behaviour: the embedded
|
|
|
6804
6818
|
| Signing in as a system user while a record session is open | permissions change, `$auth` still points at the record — only `invalidate()` clears it | 3.2.x: same as 2.x. **3.3.0**: the identity is cleared and `info()` returns `None`; `invalidate()` stays the portable log-out | v0.16.0 |
|
|
6805
6819
|
| Duplicate signin identifier in the record table | signin fails (`No record was returned`) | signin succeeds, picking one record | v0.16.0 |
|
|
6806
6820
|
| Model auth (`signup`/`signin`/`authenticate`, `access_ddl`/`define_access`) | same on both lines (verified on 2.6.5) | same on both lines (verified on 3.2.4) | v0.17.0 |
|
|
6821
|
+
| Model auth with a `primary_key` (`access_ddl()`, `define_access()`) | same on both lines: SIGNUP runs `CREATE <table> SET id = $<key>, …`, so the record id is the key (verified on 2.7.0) | same on both lines (verified on 3.3.4 and 3.1.5); v0.17.0 to v0.37.1 rendered `type::thing`, which 3.x refuses, so `define_access()` failed | v0.37.2 |
|
|
6807
6822
|
| Model auth session isolation (each call on its own ephemeral connection) | same on both lines (an SDK/connection property, not a server one) | same on both lines (verified on 3.2.4) | v0.17.0 |
|
|
6808
6823
|
| Hydrated instance's password field after `signup`/`signin` | holds the stored **hash**, never the plaintext | same on both lines | v0.17.0 |
|
|
6809
6824
|
| Model config `with_refresh=True` → `define_access()` | raises `SurrealDbError` (clause does not parse; message names the 3.x requirement) | applies, and `AuthResult.tokens.refresh` is populated | v0.17.0 |
|
|
@@ -2491,8 +2491,10 @@ def parse_define_access(text: str) -> AccessState:
|
|
|
2491
2491
|
``BEARER``) is read positionally, then the clauses ``SIGNUP``, ``SIGNIN``, ``WITH REFRESH``, ``WITH JWT``,
|
|
2492
2492
|
``ALGORITHM``, ``URL``, ``WITH ISSUER``, ``AUTHENTICATE``, ``DURATION`` and ``COMMENT``. ``signup`` and ``signin``
|
|
2493
2493
|
keep their groups, parentheses included. ``table`` and ``signup_fields`` come from a SIGNUP ``CREATE <target> SET
|
|
2494
|
-
<field> = <expr>, …`` whose target is a table name
|
|
2495
|
-
``
|
|
2494
|
+
<field> = <expr>, …`` whose target is a table name — ``define_access()``'s form, whose ``id = $<key>`` item for a
|
|
2495
|
+
``primary_key`` is one of the ``signup_fields`` — or a guarded ``type::thing('<table>', …)`` /
|
|
2496
|
+
``type::record('<table>', …)`` call (the ORM's ``primary_key`` form before #338, or one written by hand), every
|
|
2497
|
+
``SET`` item read; ``signin_where`` from a SIGNIN ``SELECT … FROM <table> WHERE <expr>``; any
|
|
2496
2498
|
other shape gives ``""`` and ``{}``, with no error (the full ORM's attributes, made exact). Durations are kept as
|
|
2497
2499
|
rendered (``"4w2d"``, ``"NONE"``), ``None`` for one the ``DURATION`` clause does not name. The servers render the
|
|
2498
2500
|
keys ``[REDACTED]``. Raises ``DefineParseError``.
|
|
@@ -170,7 +170,8 @@ class AuthenticatedUserMixin:
|
|
|
170
170
|
a ``primary_key`` — otherwise the instance these methods return cannot be constructed at
|
|
171
171
|
all. Prefer the ``id`` field here: SIGNUP lets the server mint the record id, and this is
|
|
172
172
|
what receives it. Configure ``primary_key`` instead when the identity *is* a column (say
|
|
173
|
-
the e-mail address), and the SIGNUP clause will
|
|
173
|
+
the e-mail address), and the SIGNUP clause will set the record id from it (``id = $email``)
|
|
174
|
+
accordingly — the same statement on SurrealDB 3.x, 2.x and the embedded engine.
|
|
174
175
|
"""
|
|
175
176
|
|
|
176
177
|
# ------------------------------------------------------------------
|
|
@@ -303,11 +304,12 @@ class AuthenticatedUserMixin:
|
|
|
303
304
|
def _signup_primary_key(cls) -> str | None:
|
|
304
305
|
"""The primary key SIGNUP builds the record id from, or ``None`` for a server id.
|
|
305
306
|
|
|
306
|
-
The key has to be *bindable*: SIGNUP renders ``
|
|
307
|
-
is not among the fields signup sends would evaluate to ``
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
bound. Caught here, at render time,
|
|
307
|
+
The key has to be *bindable*: SIGNUP renders ``CREATE <table> SET id = $pk, …``, so a key
|
|
308
|
+
that is not among the fields signup sends would evaluate to ``id = NONE`` and have the
|
|
309
|
+
server mint a random record id — one no ``objects().get(<key>)`` addresses.
|
|
310
|
+
``primary_key="id"`` is the trap — ``id`` is deliberately excluded from the signup
|
|
311
|
+
payload (the server mints it), so it can never be bound. Caught here, at render time,
|
|
312
|
+
rather than on every signup.
|
|
311
313
|
"""
|
|
312
314
|
primary_key = cls.get_index_primary_key() # type: ignore[attr-defined]
|
|
313
315
|
if primary_key is None:
|
|
@@ -385,6 +387,12 @@ class AuthenticatedUserMixin:
|
|
|
385
387
|
``define_table()`` writes ``TYPE NORMAL``, so calling both changes the type each time.
|
|
386
388
|
Declaring ``table_type`` gives both the same type.
|
|
387
389
|
|
|
390
|
+
A model with a ``primary_key`` has SIGNUP create the record whose id is the key:
|
|
391
|
+
``CREATE <table> SET id = $<key>, …``, the assignment first (#338). The statements are
|
|
392
|
+
the same for SurrealDB 3.x, 2.x and the embedded engine — a function building the id
|
|
393
|
+
would not be: 3.x refuses ``type::thing`` at ``DEFINE``, and 2.x reads
|
|
394
|
+
``type::record(table, key)`` as a type check that fails every signup.
|
|
395
|
+
|
|
388
396
|
Args:
|
|
389
397
|
overwrite: ``True`` (default) emits ``OVERWRITE`` — the model is the source of
|
|
390
398
|
truth, so re-running converges the database onto the code. ``False`` emits
|
|
@@ -451,9 +459,13 @@ class AuthenticatedUserMixin:
|
|
|
451
459
|
|
|
452
460
|
# The record id follows the model's primary key, because the rest of the ORM does: a
|
|
453
461
|
# random id here would leave User.objects().get(email=…) addressing a record the
|
|
454
|
-
# signup never wrote.
|
|
462
|
+
# signup never wrote. It is assigned from the bound key (`id = $<key>`, first item of
|
|
463
|
+
# the SET), not built with a function: SurrealDB 3.x refuses `type::thing` at DEFINE,
|
|
464
|
+
# and 2.x reads `type::record(table, key)` as a type check that fails every signup
|
|
465
|
+
# (#338), while the assignment gives the record id `<table>:<key>` on both lines and on
|
|
466
|
+
# the embedded engine.
|
|
455
467
|
primary_key = cls._signup_primary_key()
|
|
456
|
-
|
|
468
|
+
items = [] if primary_key is None else [f"id = ${primary_key}"]
|
|
457
469
|
|
|
458
470
|
# Column on the left of each assignment, bound variable on the right: the variable
|
|
459
471
|
# keeps the Python name the caller passes as a keyword argument, while the column is
|
|
@@ -462,16 +474,16 @@ class AuthenticatedUserMixin:
|
|
|
462
474
|
# `password_hash` — signin would then keep validating against a hash no ORM write ever
|
|
463
475
|
# updates.
|
|
464
476
|
to_column = cls.to_db_field # type: ignore[attr-defined]
|
|
465
|
-
|
|
477
|
+
items += [
|
|
466
478
|
f"{to_column(name)} = crypto::{algorithm}::generate(${name})"
|
|
467
479
|
if name == password
|
|
468
480
|
else f"{to_column(name)} = ${name}"
|
|
469
481
|
for name in cls._signup_fields()
|
|
470
|
-
|
|
482
|
+
]
|
|
471
483
|
|
|
472
484
|
parts = [
|
|
473
485
|
f"DEFINE ACCESS {clause} {access} ON DATABASE TYPE RECORD",
|
|
474
|
-
f"SIGNUP ( CREATE {
|
|
486
|
+
f"SIGNUP ( CREATE {table} SET {', '.join(items)} )",
|
|
475
487
|
f"SIGNIN ( SELECT * FROM {table} WHERE {to_column(identifier)} = ${identifier} "
|
|
476
488
|
f"AND crypto::{algorithm}::compare({to_column(password)}, ${password}) )",
|
|
477
489
|
]
|
|
@@ -654,6 +666,14 @@ class AuthenticatedUserMixin:
|
|
|
654
666
|
f"They have no default, so the instance could not be built from the record "
|
|
655
667
|
f"the server would create."
|
|
656
668
|
)
|
|
669
|
+
# The record id SIGNUP creates is the primary key's value (`SET id = $<key>`, #338): a
|
|
670
|
+
# `None` there has the server mint a random id, one no objects().get(<key>) addresses —
|
|
671
|
+
# refused before the exchange as well.
|
|
672
|
+
primary_key = cls.get_index_primary_key() # type: ignore[attr-defined]
|
|
673
|
+
if primary_key in payload and payload[primary_key] is None:
|
|
674
|
+
raise ValueError(
|
|
675
|
+
f"{cls.__name__}.{action}() requires {primary_key}=: it is the primary key, which SIGNUP makes the record id."
|
|
676
|
+
)
|
|
657
677
|
return payload
|
|
658
678
|
|
|
659
679
|
@classmethod
|
|
@@ -964,7 +984,8 @@ class AuthenticatedUserMixin:
|
|
|
964
984
|
would strip of its password hash. :meth:`signin`, :meth:`authenticate`,
|
|
965
985
|
:meth:`refresh`, ``update()`` and ``upsert()`` refuse such a model the same way
|
|
966
986
|
(#310), whoever wrote the record.
|
|
967
|
-
ValueError: for an unknown field
|
|
987
|
+
ValueError: for an unknown field, a missing required one, or a ``primary_key`` left
|
|
988
|
+
``None`` (it is the record id SIGNUP creates) — before any request.
|
|
968
989
|
SurrealDbAuthenticationError: if the server refuses the signup, or returns no
|
|
969
990
|
record for the new session (the message says how to grant the permission).
|
|
970
991
|
SurrealDbError: on the embedded engine without ``bind=True``.
|
|
@@ -107,6 +107,7 @@ from .utils import (
|
|
|
107
107
|
format_record_id,
|
|
108
108
|
merge_extra_vars,
|
|
109
109
|
replace_content,
|
|
110
|
+
user_namespace,
|
|
110
111
|
user_stacklevel,
|
|
111
112
|
validate_alias_name,
|
|
112
113
|
validate_edge_name,
|
|
@@ -878,6 +879,16 @@ class BaseSurrealModel(BaseModel):
|
|
|
878
879
|
model from a node, so they need not import ``edge.py`` (which imports this module).
|
|
879
880
|
"""
|
|
880
881
|
|
|
882
|
+
__surreal_checks_pending__: typing.ClassVar[bool] = False
|
|
883
|
+
"""``True`` on a model Pydantic could not complete at its ``class`` statement, until it does and the vector checks
|
|
884
|
+
accept it (issue #327).
|
|
885
|
+
|
|
886
|
+
Set by ``__pydantic_init_subclass__`` when a field is still a forward reference: its vector checks then wait for
|
|
887
|
+
``__pydantic_on_complete__``, and the ORM completes the model before it reads its fields or its indexes
|
|
888
|
+
(``_complete_pending_checks()``). Read from the class's own ``__dict__`` only, never inherited: a subclass is
|
|
889
|
+
completed, and checked, on its own.
|
|
890
|
+
"""
|
|
891
|
+
|
|
881
892
|
_surreal_as_of: datetime | None = PrivateAttr(default=None)
|
|
882
893
|
"""The moment a time-travel read (``QuerySet.as_of()``) returned this instance at; ``None`` for a current record (v0.26.0).
|
|
883
894
|
|
|
@@ -980,8 +991,10 @@ class BaseSurrealModel(BaseModel):
|
|
|
980
991
|
per column and one ``Analyzer`` definition per analyzer name, one vector index per column
|
|
981
992
|
and, on a vector field of any spelling — a union with ``None`` included —, of its dimension
|
|
982
993
|
and storage type (v0.36.0) — inherited values included, the messages naming the subclass.
|
|
983
|
-
|
|
984
|
-
|
|
994
|
+
These two (``_check_vectors_and_indexes()``) read the fields Pydantic could resolve: when a
|
|
995
|
+
field is still a forward reference, the model is incomplete and they run again once Pydantic
|
|
996
|
+
completes it (``__pydantic_on_complete__()``, issue #327). So are the ``table_type``,
|
|
997
|
+
``relation_in``, ``relation_out`` and ``enforced`` keys (v0.33.0), when any of them is not ``None``: a
|
|
985
998
|
``TableType`` (``RELATION`` on an edge only), and the relation keys on an edge model only
|
|
986
999
|
(``schema.check_relation_config()``). So are, on every model and after the relation keys,
|
|
987
1000
|
the ``schema_mode``, ``changefeed``, ``permissions``, ``comment`` and
|
|
@@ -1013,12 +1026,10 @@ class BaseSurrealModel(BaseModel):
|
|
|
1013
1026
|
user=issubclass(cls, AuthenticatedUserMixin),
|
|
1014
1027
|
computed=tuple(cls.__surreal_computed__),
|
|
1015
1028
|
)
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
vectors = {cls.to_db_field(name): info for name, info in declared.items()}
|
|
1021
|
-
check_indexes_config(cls, indexes, view=cls._is_view(), column=cls.to_db_field, vectors=vectors)
|
|
1029
|
+
cls._check_vectors_and_indexes()
|
|
1030
|
+
if not cls.__pydantic_complete__:
|
|
1031
|
+
# A field still a forward reference has no Vector marker yet: checked again once the model is complete.
|
|
1032
|
+
cls.__surreal_checks_pending__ = True
|
|
1022
1033
|
relation = {key: cls.model_config.get(key) for key in ("table_type", "relation_in", "relation_out", "enforced")}
|
|
1023
1034
|
if any(value is not None for value in relation.values()):
|
|
1024
1035
|
check_relation_config(cls, edge=cls.__surreal_edge__, **relation)
|
|
@@ -1045,6 +1056,79 @@ class BaseSurrealModel(BaseModel):
|
|
|
1045
1056
|
message += " table_name wins."
|
|
1046
1057
|
warnings.warn(message, DeprecationWarning, stacklevel=user_stacklevel(also_skip=(_PYDANTIC_DIR,)))
|
|
1047
1058
|
|
|
1059
|
+
@classmethod
|
|
1060
|
+
def _check_vectors_and_indexes(cls) -> None:
|
|
1061
|
+
"""The vector checks of the ``class`` statement (v0.36.0; issues #318, #327), on the fields as Pydantic has
|
|
1062
|
+
resolved them.
|
|
1063
|
+
|
|
1064
|
+
On every model, with or without indexes, the ``Vector`` markers of the fields (``vector.declared_vectors()``):
|
|
1065
|
+
a field whose markers are ambiguous is refused, naming the model and the field. Then the ``indexes`` key
|
|
1066
|
+
(``search.check_indexes_config()``), each vector index checked against its vector field's dimension and
|
|
1067
|
+
storage type. Run by ``__pydantic_init_subclass__``, and again by ``__pydantic_on_complete__`` on a model that
|
|
1068
|
+
a forward reference left incomplete there.
|
|
1069
|
+
"""
|
|
1070
|
+
declared = declared_vectors(cls.__name__, cls.model_fields)
|
|
1071
|
+
indexes = cls.model_config.get("indexes")
|
|
1072
|
+
if indexes is not None:
|
|
1073
|
+
vectors = {cls.to_db_field(name): info for name, info in declared.items()}
|
|
1074
|
+
check_indexes_config(cls, indexes, view=cls._is_view(), column=cls.to_db_field, vectors=vectors)
|
|
1075
|
+
|
|
1076
|
+
@classmethod
|
|
1077
|
+
def __pydantic_on_complete__(cls) -> None:
|
|
1078
|
+
"""Run the vector checks of the ``class`` statement once Pydantic completes a model it could not complete
|
|
1079
|
+
there (issue #327).
|
|
1080
|
+
|
|
1081
|
+
A field annotated with a forward reference (``e: "Later" = None``) has no ``Vector`` marker until Pydantic
|
|
1082
|
+
resolves the name and completes the model: at ``model_rebuild()``, at the model's first instantiation,
|
|
1083
|
+
validation or JSON schema, or when the ORM first reads its fields or its indexes
|
|
1084
|
+
(``_complete_pending_checks()``); Pydantic calls this hook then. ``_check_vectors_and_indexes()`` runs again on
|
|
1085
|
+
every field, with the refusals of the field written directly, raised from the call that completed the model.
|
|
1086
|
+
A model complete at its ``class`` statement is checked there only: Pydantic calls this hook first, before
|
|
1087
|
+
``__pydantic_init_subclass__``, which has not asked for it (``__surreal_checks_pending__``).
|
|
1088
|
+
|
|
1089
|
+
Pydantic marks the model complete before it calls this hook, so a refusal puts the model back as it was,
|
|
1090
|
+
incomplete: each of these calls completes it again and raises the same error. The refusal is never lost.
|
|
1091
|
+
"""
|
|
1092
|
+
super().__pydantic_on_complete__()
|
|
1093
|
+
if not cls.__dict__.get("__surreal_checks_pending__", False):
|
|
1094
|
+
return
|
|
1095
|
+
try:
|
|
1096
|
+
cls._check_vectors_and_indexes()
|
|
1097
|
+
except BaseException:
|
|
1098
|
+
# Pydantic's own mocks for a model it could not complete: the next use rebuilds it, and so checks it again.
|
|
1099
|
+
from pydantic._internal._mock_val_ser import set_model_mocks
|
|
1100
|
+
|
|
1101
|
+
cls.__pydantic_complete__ = False
|
|
1102
|
+
set_model_mocks(cls)
|
|
1103
|
+
raise
|
|
1104
|
+
cls.__surreal_checks_pending__ = False
|
|
1105
|
+
|
|
1106
|
+
@classmethod
|
|
1107
|
+
def _complete_pending_checks(cls) -> None:
|
|
1108
|
+
"""Complete a model whose vector checks still wait for Pydantic (issue #327), before the ORM reads its fields
|
|
1109
|
+
or its indexes: ``_table_ddl()`` and ``_table_columns()`` (behind ``table_ddl()``, ``define_table()``),
|
|
1110
|
+
``get_indexes()`` (behind ``index_ddl()``, ``define_indexes()``, ``similar_to()``) and ``QuerySet()`` (every
|
|
1111
|
+
queryset) call it first.
|
|
1112
|
+
|
|
1113
|
+
Pydantic completes a model that a forward reference left incomplete at its ``class`` statement at
|
|
1114
|
+
``model_rebuild()`` or at its first instantiation, validation or JSON schema, never when the ORM writes its DDL
|
|
1115
|
+
or builds a query: ``define_table()`` would write the field's column ``any`` and ``define_indexes()`` a vector
|
|
1116
|
+
index its field contradicts, unchecked. So the model is rebuilt here as Pydantic's first instantiation rebuilds
|
|
1117
|
+
it — with the local names of the first caller outside the ORM (``utils.user_namespace()``), then the names of
|
|
1118
|
+
the model's module: a caller's local name wins, and the field keeps what it resolved to — and
|
|
1119
|
+
``__pydantic_on_complete__()`` runs the checks: a refusal raises from here, at every call, the model staying
|
|
1120
|
+
incomplete. A name still undefined leaves the model incomplete, read as before, without an error; the next call
|
|
1121
|
+
tries again. A complete model costs one attribute read.
|
|
1122
|
+
|
|
1123
|
+
Every model a forward reference left incomplete is completed, with or without a vector field: its columns get
|
|
1124
|
+
the resolved kinds (``define_table()`` writes ``int`` for ``score: "Score" = 0`` once ``Score = int`` is
|
|
1125
|
+
defined, not ``any``), and its links are resolved for the cross-connection check (``routing.linked_models()``),
|
|
1126
|
+
whether or not the model was instantiated first.
|
|
1127
|
+
"""
|
|
1128
|
+
if cls.__pydantic_complete__ or not cls.__dict__.get("__surreal_checks_pending__", False):
|
|
1129
|
+
return
|
|
1130
|
+
cls.model_rebuild(raise_errors=False, _types_namespace=user_namespace())
|
|
1131
|
+
|
|
1048
1132
|
@classmethod
|
|
1049
1133
|
def get_computed_fields(cls) -> dict[str, str]:
|
|
1050
1134
|
"""Return ``{field_name: SurrealQL expression}`` for this model's computed fields.
|
|
@@ -1324,7 +1408,12 @@ class BaseSurrealModel(BaseModel):
|
|
|
1324
1408
|
A tuple; ``()`` when the model declares none. A subclass inherits its parent's indexes unless it sets
|
|
1325
1409
|
``indexes`` itself (``indexes=[]`` drops them); a subclass with another table defines the same indexes on its
|
|
1326
1410
|
own table.
|
|
1411
|
+
|
|
1412
|
+
A model a forward reference left incomplete at its ``class`` statement is completed first, and checked as the
|
|
1413
|
+
``class`` statement checks a vector field (issue #327): its refusal raises here, as from :meth:`index_ddl`,
|
|
1414
|
+
:meth:`define_indexes` and ``similar_to()``.
|
|
1327
1415
|
"""
|
|
1416
|
+
cls._complete_pending_checks()
|
|
1328
1417
|
indexes = cls.model_config.get("indexes")
|
|
1329
1418
|
# Checked at the class statement: a list or tuple of Index, or None.
|
|
1330
1419
|
return tuple(indexes) if isinstance(indexes, (list, tuple)) else ()
|
|
@@ -1970,8 +2059,11 @@ class BaseSurrealModel(BaseModel):
|
|
|
1970
2059
|
|
|
1971
2060
|
Raises:
|
|
1972
2061
|
ValueError: a ``FLEXIBLE`` request on a kind without an object; a computed field's expression that is not
|
|
1973
|
-
SurrealQL the ORM can embed; ``server_fields`` names a field the model does not declare.
|
|
2062
|
+
SurrealQL the ORM can embed; ``server_fields`` names a field the model does not declare. Before them, a
|
|
2063
|
+
model a forward reference left incomplete at its ``class`` statement is completed, and its vector
|
|
2064
|
+
checks may refuse it (issue #327, ``_complete_pending_checks()``).
|
|
1974
2065
|
"""
|
|
2066
|
+
cls._complete_pending_checks()
|
|
1975
2067
|
computed = cls.get_computed_fields()
|
|
1976
2068
|
endpoints = {cls.to_py_field(column) for column in cls._endpoint_columns()}
|
|
1977
2069
|
flexible = cls.model_config.get("flexible_fields")
|
|
@@ -1997,6 +2089,7 @@ class BaseSurrealModel(BaseModel):
|
|
|
1997
2089
|
that ``Field(exclude=True)`` keeps out of ``model_dump()`` (SG1, #296, #299).
|
|
1998
2090
|
ValueError: see :meth:`_table_columns`.
|
|
1999
2091
|
"""
|
|
2092
|
+
cls._complete_pending_checks()
|
|
2000
2093
|
if cls._is_view():
|
|
2001
2094
|
return [cls.view_ddl(overwrite=overwrite)]
|
|
2002
2095
|
table = cls.get_table_name()
|
|
@@ -2061,7 +2154,8 @@ class BaseSurrealModel(BaseModel):
|
|
|
2061
2154
|
and ``signin()`` refuse the model too; remove ``exclude=True`` and pass ``exclude=`` to
|
|
2062
2155
|
``model_dump()`` where you serialise the model.
|
|
2063
2156
|
ValueError: a ``FLEXIBLE`` request on a kind without an object; a computed field's expression that is not
|
|
2064
|
-
SurrealQL the ORM can embed
|
|
2157
|
+
SurrealQL the ORM can embed; the refusals of a vector field declared through a forward reference, the
|
|
2158
|
+
``class`` statement's, checked once the name resolves (issue #327, :meth:`get_indexes`).
|
|
2065
2159
|
|
|
2066
2160
|
Example:
|
|
2067
2161
|
>>> print("\\n".join(Person.table_ddl()))
|
|
@@ -2239,7 +2333,8 @@ class BaseSurrealModel(BaseModel):
|
|
|
2239
2333
|
with a field SIGNUP writes that ``Field(exclude=True)`` keeps out of ``model_dump()``, whatever its
|
|
2240
2334
|
schema mode (see :meth:`table_ddl`) — before any request.
|
|
2241
2335
|
ValueError: a ``FLEXIBLE`` request on a kind without an object; a computed field's expression that is not
|
|
2242
|
-
SurrealQL the ORM can embed
|
|
2336
|
+
SurrealQL the ORM can embed; the refusals of a vector field declared through a forward reference
|
|
2337
|
+
(:meth:`table_ddl`) — before any request.
|
|
2243
2338
|
SurrealDbError: *tx* belongs to another connection — before any request; the table is a materialized view
|
|
2244
2339
|
or a relation table, or a table or field definition cannot be read back or carried — before any DDL;
|
|
2245
2340
|
the server refused a statement (``Can't apply table definition: …``, ``Can't apply field definition:
|
|
@@ -148,6 +148,9 @@ class QuerySet:
|
|
|
148
148
|
"""
|
|
149
149
|
|
|
150
150
|
def __init__(self, model: type[BaseSurrealModel]) -> None:
|
|
151
|
+
# Issue #327: a model a forward reference left incomplete at its class statement is completed, and its vector
|
|
152
|
+
# checks run, before a query reads its fields — their refusal raises here.
|
|
153
|
+
model._complete_pending_checks()
|
|
151
154
|
self.model = model
|
|
152
155
|
self._filters: list[tuple[str, str, Any]] = []
|
|
153
156
|
self._q_filters: list[Q] = []
|
|
@@ -279,8 +279,9 @@ class AccessState:
|
|
|
279
279
|
``signup_fields``, ``signin_where``, ``duration_token``, ``duration_session``, ``access_type``,
|
|
280
280
|
``duration_grant``. Lite additions, keyword-only: ``signup``, ``signin``, ``with_refresh``, ``comment``, ``raw``.
|
|
281
281
|
|
|
282
|
-
``table`` and ``signup_fields`` come from a ``SIGNUP (CREATE <table> SET <field> = <expr>, …)
|
|
283
|
-
|
|
282
|
+
``table`` and ``signup_fields`` come from a ``SIGNUP (CREATE <table> SET <field> = <expr>, …)`` — every item,
|
|
283
|
+
the ``id = $<key>`` of a model with a ``primary_key`` included —, ``signin_where`` from a ``SIGNIN (SELECT … FROM
|
|
284
|
+
<table> WHERE <expr>)`` (``""``/empty otherwise). Durations are kept as rendered
|
|
284
285
|
(``"15m"``, ``"NONE"``). The keys of a ``raw`` statement are already ``[REDACTED]`` by the server; ``raw``,
|
|
285
286
|
``signup``, ``signin`` and ``signin_where`` are kept out of ``repr`` all the same, and ``signup_fields`` shows its
|
|
286
287
|
keys only.
|
|
@@ -830,7 +830,8 @@ def check_indexes_config(
|
|
|
830
830
|
vectors: Mapping[str, tuple[int, str]],
|
|
831
831
|
) -> None:
|
|
832
832
|
"""The ``indexes`` key of a model's ``SurrealConfigDict``, checked when the class is defined (v0.35.0; the vector
|
|
833
|
-
indexes v0.36.0)
|
|
833
|
+
indexes v0.36.0), and again when Pydantic completes a model that a forward reference left incomplete at its
|
|
834
|
+
``class`` statement, *vectors* then holding the fields it resolved (issue #327).
|
|
834
835
|
|
|
835
836
|
``None`` (no indexes) is not passed here. The first fault raises, in this order: *value* is not a ``list`` or a
|
|
836
837
|
``tuple``; an item is not an ``Index``; two indexes share a name (the second definition would replace the first);
|
|
@@ -91,6 +91,28 @@ def user_stacklevel(*, also_skip: tuple[str, ...] = ()) -> int:
|
|
|
91
91
|
return 2
|
|
92
92
|
|
|
93
93
|
|
|
94
|
+
def user_namespace() -> dict[str, Any]:
|
|
95
|
+
"""The local names of the first frame outside the ORM (its subpackages included); ``{}`` when there is none.
|
|
96
|
+
|
|
97
|
+
Pydantic completes a model that a forward reference left incomplete at its ``class`` statement, on its first
|
|
98
|
+
instantiation, with the local names of the caller's frame, then the names of the module the model is defined in (a
|
|
99
|
+
caller's local name wins). ``BaseSurrealModel._complete_pending_checks()`` completes such a model the same way
|
|
100
|
+
before the ORM reads its fields or its indexes (issue #327): the caller is the first frame outside the ORM, whatever
|
|
101
|
+
the depth of the call.
|
|
102
|
+
"""
|
|
103
|
+
frame = inspect.currentframe()
|
|
104
|
+
try:
|
|
105
|
+
while frame is not None:
|
|
106
|
+
directory = os.path.dirname(os.path.abspath(frame.f_code.co_filename))
|
|
107
|
+
if directory != _PACKAGE_DIR and not directory.startswith(_PACKAGE_DIR + os.sep):
|
|
108
|
+
return dict(frame.f_locals)
|
|
109
|
+
frame = frame.f_back
|
|
110
|
+
return {}
|
|
111
|
+
finally:
|
|
112
|
+
# A frame refers to its locals: dropping it here keeps no reference cycle alive.
|
|
113
|
+
del frame
|
|
114
|
+
|
|
115
|
+
|
|
94
116
|
def split_statements(query: str) -> list[str]:
|
|
95
117
|
"""Split SurrealQL on the statement separator, ignoring ``;`` inside strings and comments.
|
|
96
118
|
|
|
@@ -9,10 +9,12 @@ Pydantic reads the ``Vector`` marker exactly as ``VectorField[1536]``'s. Both sp
|
|
|
9
9
|
validation, the same column type (``option<array<float, 1536>>``), the same schema. ``get_vector_info()`` and
|
|
10
10
|
``is_vector_field()`` — the full ORM's helpers, under their names — read the marker of either spelling from a model
|
|
11
11
|
field or an annotation, and of their unions with ``None`` (``VectorField[1536] | None``,
|
|
12
|
-
``Annotated[list[float], Vector(1536)] | None``), as ``define_table()`` reads
|
|
13
|
-
(``list[VectorField[3]]``). A field or an annotation holding two different markers,
|
|
14
|
-
than ``None``, has no single dimension: the helpers refuse it, and a model's ``class``
|
|
15
|
-
(``declared_vectors()``)
|
|
12
|
+
``Annotated[list[float], Vector(1536)] | None``, ``VectorField[1536] | Literal[None]``), as ``define_table()`` reads
|
|
13
|
+
them; never from inside a container (``list[VectorField[3]]``). A field or an annotation holding two different markers,
|
|
14
|
+
or a marker next to a type other than ``None``, has no single dimension: the helpers refuse it, and a model's ``class``
|
|
15
|
+
statement refuses such a field (``declared_vectors()``) — or, for a field declared through a forward reference, the
|
|
16
|
+
completion of the model once the name resolves: ``model_rebuild()``, its first instantiation, validation or JSON schema,
|
|
17
|
+
or the ORM's first DDL or queryset of the model (``BaseSurrealModel._complete_pending_checks()``).
|
|
16
18
|
|
|
17
19
|
A value is ``None`` or a ``list``/``tuple`` of exactly ``d`` real numbers — ``int``, ``float``, any ``numbers.Real``,
|
|
18
20
|
a ``decimal.Decimal`` (SurrealDB's decimals read back as ``Decimal``) —, never a ``bool`` nor a ``str``, each finite
|
|
@@ -55,7 +57,7 @@ from dataclasses import dataclass
|
|
|
55
57
|
from decimal import Decimal
|
|
56
58
|
from numbers import Real
|
|
57
59
|
from types import NoneType, UnionType
|
|
58
|
-
from typing import Annotated, Any, NoReturn, Self, TypedDict, Union, get_args, get_origin
|
|
60
|
+
from typing import Annotated, Any, Literal, NoReturn, Self, TypedDict, Union, get_args, get_origin
|
|
59
61
|
|
|
60
62
|
from pydantic import Field, GetCoreSchemaHandler, GetJsonSchemaHandler
|
|
61
63
|
from pydantic.fields import FieldInfo
|
|
@@ -303,9 +305,11 @@ def _held(annotation: Any, metadata: Sequence[Any] = ()) -> tuple[tuple[Vector,
|
|
|
303
305
|
|
|
304
306
|
The ``Annotated`` layers are unwrapped and their metadata added to *metadata*: when it holds a ``Vector``, those
|
|
305
307
|
markers decide, whatever the type under them (a ``Vector`` validates the value itself). Otherwise ``None`` gives
|
|
306
|
-
neither
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
neither, and so does a ``Literal`` whose values are all ``None`` (``Literal[None]`` admits ``None`` only, issue
|
|
309
|
+
#327); a union gives the markers and other types of its members, each read the same way; any other type is
|
|
310
|
+
another type — a ``Literal`` holding another value (``Literal[None, "x"]``) and a container holding vectors
|
|
311
|
+
(``list[VectorField[3]]``) included, whose arguments are never read. This is the reading ``model_ddl`` gives the
|
|
312
|
+
column its kind by, so the column and the checks agree.
|
|
309
313
|
"""
|
|
310
314
|
while get_origin(annotation) is Annotated:
|
|
311
315
|
metadata = (*metadata, *annotation.__metadata__)
|
|
@@ -313,9 +317,9 @@ def _held(annotation: Any, metadata: Sequence[Any] = ()) -> tuple[tuple[Vector,
|
|
|
313
317
|
markers = tuple(dict.fromkeys(item for item in metadata if isinstance(item, Vector)))
|
|
314
318
|
if markers:
|
|
315
319
|
return markers, False
|
|
316
|
-
if annotation is None or annotation is NoneType:
|
|
317
|
-
return (), False
|
|
318
320
|
origin = get_origin(annotation)
|
|
321
|
+
if annotation is None or annotation is NoneType or (origin is Literal and all(arg is None for arg in get_args(annotation))):
|
|
322
|
+
return (), False
|
|
319
323
|
if origin is not Union and origin is not UnionType:
|
|
320
324
|
return (), True
|
|
321
325
|
members = [_held(member) for member in get_args(annotation)]
|
|
@@ -360,30 +364,35 @@ def get_vector_info(annotation_or_field: Any) -> tuple[int, str] | None:
|
|
|
360
364
|
Takes a model field (``Model.model_fields["embedding"]``, a Pydantic ``FieldInfo``) or an annotation
|
|
361
365
|
(``VectorField[3]``, ``Annotated[list[float] | None, Vector(3)]``): both spellings give ``(3, "F32")``, and so do
|
|
362
366
|
their unions with ``None`` (``VectorField[3] | None``, ``Optional[VectorField[3]]``,
|
|
363
|
-
``Annotated[list[float], Vector(3)] | None``), read as ``define_table()`` reads
|
|
364
|
-
marker — ``list[float]``, another field, vectors held in a container such as
|
|
365
|
-
``None``.
|
|
367
|
+
``Annotated[list[float], Vector(3)] | None``, ``VectorField[3] | Literal[None]``), read as ``define_table()`` reads
|
|
368
|
+
them. Anything without a ``Vector`` marker — ``list[float]``, another field, vectors held in a container such as
|
|
369
|
+
``list[VectorField[3]]`` — gives ``None``.
|
|
366
370
|
|
|
367
371
|
:raises ValueError: the field or annotation holds two different ``Vector`` markers, or a marker next to a type
|
|
368
|
-
other than ``None`` in a union (``VectorField[3] | str``): its
|
|
369
|
-
model's ``class`` statement refuses such a field already, naming it
|
|
372
|
+
other than ``None`` in a union (``VectorField[3] | str``, ``VectorField[3] | Literal[None, "x"]``): its
|
|
373
|
+
dimension and storage type are not one. A model's ``class`` statement refuses such a field already, naming it
|
|
374
|
+
(for a field declared through a forward reference, once Pydantic completes the model).
|
|
370
375
|
"""
|
|
371
376
|
marker = _marker(annotation_or_field)
|
|
372
377
|
return None if marker is None else (marker.dimension, marker.vector_type)
|
|
373
378
|
|
|
374
379
|
|
|
375
380
|
def is_vector_field(annotation_or_field: Any) -> bool:
|
|
376
|
-
"""Whether a model field or an annotation is a vector field, any spelling — a union with ``None``
|
|
377
|
-
full ORM's helper). Refuses what ``get_vector_info()`` refuses, with its
|
|
381
|
+
"""Whether a model field or an annotation is a vector field, any spelling — a union with ``None`` or
|
|
382
|
+
``Literal[None]`` included — (the full ORM's helper). Refuses what ``get_vector_info()`` refuses, with its
|
|
383
|
+
``ValueError``: a field or an annotation holding two different ``Vector`` markers, or a marker next to a type other
|
|
384
|
+
than ``None``."""
|
|
378
385
|
return _marker(annotation_or_field) is not None
|
|
379
386
|
|
|
380
387
|
|
|
381
388
|
def declared_vectors(owner: str, fields: Mapping[str, FieldInfo]) -> dict[str, tuple[int, str]]:
|
|
382
389
|
"""The ``(dimension, storage type)`` of each vector field among a model's *fields*, by field name, as
|
|
383
|
-
``get_vector_info()`` reads them: what the model's ``class`` statement checks (issue #318)
|
|
390
|
+
``get_vector_info()`` reads them: what the model's ``class`` statement checks (issue #318), and checks again once
|
|
391
|
+
Pydantic completes a model a forward reference left incomplete there (issue #327).
|
|
384
392
|
|
|
385
393
|
A field whose ``Vector`` markers are ambiguous raises ``ValueError`` naming the model *owner* and the field, so the
|
|
386
|
-
``class`` statement refuses it whether or not the model declares indexes.
|
|
394
|
+
``class`` statement refuses it whether or not the model declares indexes. A field still a forward reference has no
|
|
395
|
+
marker yet: it is not a vector field here.
|
|
387
396
|
"""
|
|
388
397
|
declared: dict[str, tuple[int, str]] = {}
|
|
389
398
|
for name, field in fields.items():
|
|
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
|
{surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/connection_config.py
RENAMED
|
File without changes
|
{surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/connection_manager.py
RENAMED
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/__init__.py
RENAMED
|
File without changes
|
{surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/database.py
RENAMED
|
File without changes
|
{surreal_orm_lite-0.37.0 → surreal_orm_lite-0.37.2}/src/surreal_orm_lite/testing/fixtures.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|