-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a client code hook for controlling model truthiness #110
Comments
Type for class ModelBoolPredicate(Protocol):
def __call__(self, model: _TModelInstance) -> bool: ... |
Example for
|
Note that it would currently NOT be possible to achieve {
"items": [
{
"parent": "x",
"children": [
{
"name": "foo",
}
]
},
{
"parent": "y",
"children": [
{
"name": null,
},
{
"name": null,
}
]
},
{
"parent": "z",
"children": [ ]
}
],
"page": 1,
"size": 100,
"total": 3,
"pages": 1
} by excluding a model field from serialization like so: class Child(BaseModel):
model_config = ConfigDict(model_bool="child")
child: str | None = Field(default=None, exclude=True)
name: str | None = None This is due the |
This might actually be a very easy fix, instead of calling See #112 . |
The tests cover all cases discussed in #110.
The tests cover all cases discussed in #110.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature provides the option for client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the rdfproxy grouping mechanism. Currently, a model is considered truthy if at least one of its fields is truthy. This is a sane default, yet certain frontend demands require different model truth conditions. The feature introduces a model_bool option in the model_config that allows client code to specify conditions/predicates for determining model truthiness. Closes #110, closes #112.
The tests cover all cases discussed in #110.
Model truthiness is an important metric for the
rdfproxy
grouping mechanism. Currently, the logic for determining model truthiness is hard-coded to recognize a model as truthy if any of its fields is truthy, (seerdfproxy.mapper.ModelBindingsMapper._get_unique_models
line 35).This is a sane default, yet certain frontend demands require different model truth conditions.
Current behavior
With the current implementation, a simple model definition like
yields the following result:
According to the currently hard-coded truth condition for model instances, a model is truthy if any of its fields is truthy; so the above configuration correctly returns empty arrays for
y
andz
children
, because for those rows, the singleChild
fieldname
is None.However, it might very well be desirable for backend implementers and API consumers to differentiate between "no object" and "an object with a single
null
value/onlynull
values". Currently, this is not possible.Solution proposal
A solution for this is to provide a hook for allowing client code to control the conditions for model instance truthiness by supporting a
model_bool
field inpydantic.ConfigDict
.The
model_bool
property would accept arguments of typeCallable
Client code may provide a callable of arity 1 which receives the model instance as argument at runtime.
str
A string value for
model_bool
defines the truthiness of the field denoted by that string value as general truth condition for the model.Iterable[str]
An
Iterable[str]
value formodel_bool
defines the truthiness of the model as the conjunction of all fields referenced in the iterable, i.e. the model is only considered to be truthy if all the referenced fields have truthy values.This way it would be possible to adapt the above example to allow objects with only a single
null
value like so:The expected result would then be:
The text was updated successfully, but these errors were encountered: