Helpful Decorators

Helpful decorators.

odin.decorators.returns_resource(func: _F = None, codec=None, resource: Type[ResourceBase] = None, full_clean: bool = True, codec_opts: Dict[str, Any] = None) _F | Callable[[_F], _F][source]

Apply to a function that returns data that can be converted into a resource (or resources).

If a codec is provided the data will be converted using the codec, if not it will be assumed that the supplied data is a dictionary that can be converted into a resource.

Note that this decorator can raise ValidationError exceptions.

Parameters:
  • func – Function being wrapped

  • codec – Optional codec that should be used to convert data.

  • resource – Optional resource to convert to (only required if the data does not contain a resource identifier).

  • full_clean – Perform a full clean on the data post conversion.

  • codec_opts – Options that should be supplied ot the codec.

Returns:

Resource, Array of resources or None.