pydantic-forms 2.10.0__tar.gz → 2.10.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.
Files changed (85) hide show
  1. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/PKG-INFO +1 -1
  2. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/core/shared.py +2 -19
  3. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/options_source.py +15 -0
  4. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pyproject.toml +1 -1
  5. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pyproject.toml.orig +1 -1
  6. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_options_source.py +34 -7
  7. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/LICENSE +0 -0
  8. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/README.md +0 -0
  9. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/__init__.py +0 -0
  10. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/core/__init__.py +0 -0
  11. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/core/asynchronous.py +0 -0
  12. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/core/sync.py +0 -0
  13. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/core/translations.py +0 -0
  14. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/exception_handlers/__init__.py +0 -0
  15. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/exception_handlers/fastapi.py +0 -0
  16. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/exceptions.py +0 -0
  17. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/py.typed +0 -0
  18. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/types.py +0 -0
  19. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/utils/__init__.py +0 -0
  20. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/utils/json.py +0 -0
  21. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/utils/pointer.py +0 -0
  22. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/utils/schema.py +0 -0
  23. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/__init__.py +0 -0
  24. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/__init__.py +0 -0
  25. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/accept.py +0 -0
  26. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/buttons.py +0 -0
  27. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/callout.py +0 -0
  28. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/choice.py +0 -0
  29. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/choice_list.py +0 -0
  30. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/contact_person.py +0 -0
  31. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/contact_person_list.py +0 -0
  32. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/display_subscription.py +0 -0
  33. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/divider.py +0 -0
  34. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/hidden.py +0 -0
  35. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/label.py +0 -0
  36. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/layout.py +0 -0
  37. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/list_of_one.py +0 -0
  38. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/list_of_two.py +0 -0
  39. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/long_text.py +0 -0
  40. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/markdown.py +0 -0
  41. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/migration_summary.py +0 -0
  42. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/organisation_id.py +0 -0
  43. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/read_only.py +0 -0
  44. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/timestamp.py +0 -0
  45. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/components/unique_constrained_list.py +0 -0
  46. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/constants.py +0 -0
  47. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/pydantic_forms/validators/helpers.py +0 -0
  48. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/__init__.py +0 -0
  49. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/paths.py +0 -0
  50. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/__init__.py +0 -0
  51. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/exception_handlers/__init__.py +0 -0
  52. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/exception_handlers/test_fastapi.py +0 -0
  53. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/helpers.py +0 -0
  54. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_accept.py +0 -0
  55. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_buttons.py +0 -0
  56. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_callout.py +0 -0
  57. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_choice.py +0 -0
  58. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_choice_list.py +0 -0
  59. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_constrained_list.py +0 -0
  60. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_contact_person.py +0 -0
  61. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_contact_person_list.py +0 -0
  62. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_core.py +0 -0
  63. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_core_async.py +0 -0
  64. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_default_factory.py +0 -0
  65. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_display_subscription.py +0 -0
  66. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_divider.py +0 -0
  67. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_documentation.py +0 -0
  68. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_form_meta.py +0 -0
  69. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_hidden.py +0 -0
  70. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_label.py +0 -0
  71. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_layout.py +0 -0
  72. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_list_of_one.py +0 -0
  73. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_list_of_two.py +0 -0
  74. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_long_text.py +0 -0
  75. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_markdown.py +0 -0
  76. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_migration_summary.py +0 -0
  77. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_organisation_id.py +0 -0
  78. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_page_schema.py +0 -0
  79. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_read_only_field.py +0 -0
  80. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_shared.py +0 -0
  81. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_timestamp.py +0 -0
  82. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_utils_dict_without_none.py +0 -0
  83. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_utils_from_serializable.py +0 -0
  84. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_utils_to_serializable.py +0 -0
  85. {pydantic_forms-2.10.0 → pydantic_forms-2.10.2}/tests/unit_tests/test_walk.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-forms
3
- Version: 2.10.0
3
+ Version: 2.10.2
4
4
  Summary: Pydantic-forms engine.
5
5
  Author: SURF
6
6
  Author-email: SURF <automation-beheer@surf.nl>
@@ -20,7 +20,6 @@ from pydantic import (
20
20
  ConfigDict,
21
21
  Field,
22
22
  PydanticUndefinedAnnotation,
23
- PydanticUserError,
24
23
  ValidationError,
25
24
  version,
26
25
  )
@@ -109,19 +108,6 @@ class FormPage(BaseModel):
109
108
  """Return `meta__` with the page's `ButtonsConfig` field added."""
110
109
  return merge_buttons_into_meta(cls.__name__, cls.meta__, cls.model_fields)
111
110
 
112
- @classmethod
113
- def _check_options_sources(cls) -> None:
114
- """Refuse a sourced field whose pointer reaches no field now, as the page is defined, not when it is first sent.
115
-
116
- A page whose JSON schema cannot be made yet (a forward reference still unresolved) or at all (an arbitrary
117
- type) is left alone here; ``page_schema`` reports on it later, as it does today.
118
- """
119
- try:
120
- schema = cls.model_json_schema()
121
- except (PydanticUserError, PydanticUndefinedAnnotation):
122
- return
123
- schema_utils.check_options_sources(schema, cls.__name__)
124
-
125
111
  if PYDANTIC_VERSION in ("2.9", "2.10", "2.11"):
126
112
 
127
113
  @classmethod
@@ -154,7 +140,6 @@ class FormPage(BaseModel):
154
140
  undefined_annotation=exc.name,
155
141
  model=cls.__name__,
156
142
  )
157
- cls._check_options_sources()
158
143
 
159
144
  else: # pydantic >= 2.12
160
145
 
@@ -173,7 +158,6 @@ class FormPage(BaseModel):
173
158
 
174
159
  if needs_rebuild:
175
160
  cls.model_rebuild(force=True)
176
- cls._check_options_sources()
177
161
 
178
162
 
179
163
  FORMS: dict[str, Callable] = {}
@@ -248,9 +232,8 @@ def page_schema(page: type[BaseModel], *, inline_refs: bool = False) -> JsonSche
248
232
  With ``inline_refs`` every ``$ref`` to a ``$defs`` entry is replaced by that entry, so a program gets one
249
233
  self-contained document per page; see ``pydantic_forms.utils.schema.inline_refs``.
250
234
 
251
- Raises ``ValueError`` when a field's ``OptionsSource`` points at a field the page does not have. A ``FormPage``
252
- already refuses such a field when it is defined; this is the check for any other model yielded as a page, and
253
- for a ``FormPage`` whose schema could not be made at that time. See
235
+ Raises ``ValueError`` when a field's ``OptionsSource`` points at a field the page does not have, whether the page
236
+ is a ``FormPage`` or any other model yielded as a page. See
254
237
  ``pydantic_forms.utils.schema.check_options_sources``.
255
238
  """
256
239
  schema = page.model_json_schema(schema_generator=GenerateFormJsonSchema)
@@ -24,6 +24,8 @@ from pydantic_forms.utils.schema import DEPENDS_ON, OPTIONS_SOURCE
24
24
 
25
25
  # A ``{name}`` in the url, filled by the client with the value ``depends_on[name]`` points at.
26
26
  _PLACEHOLDER = re.compile(r"\{([^{}]*)\}")
27
+ # The placeholder of ``lookup`` that stands for the field's own value.
28
+ _LOOKUP_VALUE = "value"
27
29
 
28
30
 
29
31
  @dataclass(frozen=True)
@@ -41,6 +43,11 @@ class OptionsSource:
41
43
  in the path or the query string, is filled with the URL-encoded value `depends_on[name]` points at.
42
44
  search: Name of the query parameter that narrows the list on the server. Without it a client fetches
43
45
  the list once and filters it itself.
46
+ lookup: URL of one option, such as `"/api/customers/{value}"`: `{value}` is filled with the URL-encoded
47
+ value of the field, any other placeholder as in `url`. The response is one item, read with `value`
48
+ and `label` as an item of the list is; a 404 says the value is not an option. With it a client
49
+ labels a value it already has, and checks that it is an option, without the list: declare it beside
50
+ `search`, where the list is never whole.
44
51
  items: JSON pointer to the list inside the response, such as `"/data/customers"`. Without it the
45
52
  response is the list.
46
53
  value: Key of an item that is the field's value. Without it the item itself is, as for a list of strings.
@@ -55,6 +62,7 @@ class OptionsSource:
55
62
 
56
63
  url: str
57
64
  search: str | None = None
65
+ lookup: str | None = None
58
66
  items: str | None = None
59
67
  value: str | None = None
60
68
  label: str | None = None
@@ -73,6 +81,12 @@ class OptionsSource:
73
81
  pointers = dict(self.depends_on or {})
74
82
  if unmapped := placeholders - pointers.keys():
75
83
  raise ValueError(f"url names {sorted(unmapped)}, which depends_on does not map to a field")
84
+ if self.lookup is not None:
85
+ named = set(_PLACEHOLDER.findall(self.lookup))
86
+ if _LOOKUP_VALUE not in named or _LOOKUP_VALUE in pointers:
87
+ raise ValueError("lookup must name {value}, the field's own value, which depends_on does not map")
88
+ if unmapped := named - pointers.keys() - {_LOOKUP_VALUE}:
89
+ raise ValueError(f"lookup names {sorted(unmapped)}, which depends_on does not map to a field")
76
90
  if unused := pointers.keys() - placeholders:
77
91
  raise ValueError(f"depends_on maps {sorted(unused)}, which url does not name")
78
92
  if invalid := {name: pointer for name, pointer in pointers.items() if parse_pointer(pointer) is None}:
@@ -82,6 +96,7 @@ class OptionsSource:
82
96
  keys: dict[str, Any] = {
83
97
  "url": self.url,
84
98
  "search": self.search,
99
+ "lookup": self.lookup,
85
100
  "items": self.items,
86
101
  "value": self.value,
87
102
  "label": self.label,
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "pydantic-forms"
3
3
  description = "Pydantic-forms engine."
4
- version = "2.10.0"
4
+ version = "2.10.2"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  license-files = ["LICENSE"]
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "pydantic-forms"
3
3
  description = "Pydantic-forms engine."
4
- version = "2.10.0"
4
+ version = "2.10.2"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  license-files = ["LICENSE"]
@@ -86,6 +86,7 @@ def test_every_key_is_emitted_in_camel_case_and_unset_ones_are_left_out():
86
86
  OptionsSource(
87
87
  url="/api/locations/{location}/nodes?status=active",
88
88
  search="q",
89
+ lookup="/api/locations/{location}/nodes/{value}",
89
90
  items="/data/nodes",
90
91
  value="id",
91
92
  label="{name} ({status})",
@@ -96,6 +97,7 @@ def test_every_key_is_emitted_in_camel_case_and_unset_ones_are_left_out():
96
97
  assert page_schema(Form)["properties"]["node"]["optionsSource"] == {
97
98
  "url": "/api/locations/{location}/nodes?status=active",
98
99
  "search": "q",
100
+ "lookup": "/api/locations/{location}/nodes/{value}",
99
101
  "items": "/data/nodes",
100
102
  "value": "id",
101
103
  "label": "{name} ({status})",
@@ -242,17 +244,18 @@ def test_a_pointer_that_reaches_a_field_is_accepted(pointer):
242
244
  pytest.param("/ports/node", id="a-name-where-an-index-is-due"),
243
245
  ],
244
246
  )
245
- def test_a_pointer_that_reaches_no_field_is_refused_as_the_page_is_defined(pointer):
247
+ def test_a_pointer_that_reaches_no_field_is_refused_when_its_schema_is_made(pointer):
246
248
  class Row(BaseModel):
247
249
  node: int
248
250
  port: Annotated[int, OptionsSource(url="/api/ports?by={x}", depends_on={"x": pointer})]
249
251
 
252
+ class Form(FormPage):
253
+ service_speed: int
254
+ ports: list[Row]
255
+
250
256
  expected = f"Form: /properties/ports/items/properties/port fills 'x' from '{pointer}', which points at no field"
251
257
  with pytest.raises(ValueError, match=re.escape(expected)):
252
-
253
- class Form(FormPage):
254
- service_speed: int
255
- ports: list[Row]
258
+ page_schema(Form)
256
259
 
257
260
 
258
261
  def test_a_page_that_is_a_plain_model_is_refused_when_its_schema_is_made():
@@ -336,7 +339,7 @@ def test_a_pointer_follows_a_model_into_itself(pointer, accepted):
336
339
  assert "/properties/pick" in options_sources(page_schema(page()))
337
340
  else:
338
341
  with pytest.raises(ValueError, match="/properties/pick fills 'name'"):
339
- page()
342
+ page_schema(page())
340
343
 
341
344
 
342
345
  @pytest.mark.parametrize(
@@ -358,7 +361,22 @@ def test_a_pointer_names_the_field_as_the_schema_does(pointer, accepted):
358
361
  assert options_sources(page_schema(page()))["/properties/contact"]["dependsOn"] == {"c": pointer}
359
362
  else:
360
363
  with pytest.raises(ValueError, match="/properties/contact fills 'c'"):
361
- page()
364
+ page_schema(page())
365
+
366
+
367
+ def test_defining_a_page_does_not_run_json_schema_extra_callbacks():
368
+ calls = []
369
+
370
+ def options(schema: dict[str, Any]) -> None:
371
+ calls.append(schema)
372
+
373
+ class Page(FormPage):
374
+ choice: str = Field(json_schema_extra=options)
375
+
376
+ assert calls == []
377
+
378
+ assert page_schema(Page)["properties"]["choice"]["type"] == "string"
379
+ assert len(calls) == 1
362
380
 
363
381
 
364
382
  def test_the_source_does_not_change_validation():
@@ -398,6 +416,15 @@ def test_the_source_does_not_change_validation():
398
416
  {"url": "/a/{b}", "depends_on": {"b": "/a~2b"}}, "is not a JSON pointer", id="a-tilde-that-escapes-nothing"
399
417
  ),
400
418
  pytest.param({"url": "/a/{b}", "depends_on": {"b": "1/a~"}}, "is not a JSON pointer", id="a-tilde-at-the-end"),
419
+ pytest.param({"url": "/a", "lookup": "/a/one"}, "lookup must name {value}", id="a-lookup-without-the-value"),
420
+ pytest.param(
421
+ {"url": "/a/{value}", "lookup": "/a/{value}", "depends_on": {"value": "1/b"}},
422
+ "lookup must name {value}",
423
+ id="a-lookup-whose-value-is-another-field",
424
+ ),
425
+ pytest.param(
426
+ {"url": "/a", "lookup": "/a/{b}/{value}"}, r"lookup names \['b'\]", id="a-lookup-placeholder-not-mapped"
427
+ ),
401
428
  pytest.param({"url": "/a", "items": "data"}, "items must be a JSON pointer", id="items-that-is-no-pointer"),
402
429
  pytest.param({"url": "/a", "items": "/a~2b"}, "items must be a JSON pointer", id="items-with-a-bad-escape"),
403
430
  ],
File without changes