# google.appengine.api.validation.Preferred

<br />

|---|
| [View source on GitHub](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L1469-L1510) |

A non-deprecated field when there's a deprecated one.

Inherits From: [`Normalized`](https://docs.cloud.google.com/appengine/docs/standard/python3/reference/services/bundled/google/appengine/api/validation/Normalized), [`Validator`](https://docs.cloud.google.com/appengine/docs/standard/python3/reference/services/bundled/google/appengine/api/validation/Validator), [`expected_type`](https://docs.cloud.google.com/appengine/docs/standard/python3/reference/services/bundled/google/appengine/api/validation/Validator/expected_type)

    google.appengine.api.validation.Preferred(
        deprecated, validator, default=None
    )

For use with Deprecated. Only works as a field on `Validated`.

Both fields will work for value access. It's an error to set both the
deprecated and the corresponding preferred field.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `deprecated` | The name of the corresponding deprecated field |
| `validator` | The validator for the actual value of this field. |
| `default` | The default value for this field. |

<br />

## Child Classes

[`class expected_type`](https://docs.cloud.google.com/appengine/docs/standard/python3/reference/services/bundled/google/appengine/api/validation/Validator/expected_type)

## Methods

### `CheckFieldInitialized`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L1493-L1502)

    CheckFieldInitialized(
        value, key, obj
    )

Check for missing fields or conflicts between fields.

Default behavior performs a simple `None`-check, but this can be overridden.
If the intent is to allow optional fields, then use the `Optional` validator
instead.

<br />

<br />

<br />

| Args ||
|---|---|
| `value` | Value to validate. |
| `key` | Name of the field being validated. |
| `obj` | The object to validate against. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValidationError` | When there are missing or conflicting fields. |

<br />

### `Get`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L1504-L1510)

    Get(
        value, key, obj
    )

Returns the normalized value. Subclasses must override.

### `GetWarnings`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L722-L738)

    GetWarnings(
        value, key, obj
    )

Return any warnings on this attribute.

Validates the value with an eye towards things that aren't fatal problems.

<br />

<br />

<br />

| Args ||
|---|---|
| `value` | Value to validate. |
| `key` | Name of the field being validated. |
| `obj` | The object to validate against. |

<br />

<br />

<br />

| Returns ||
|---|---|
| A list of tuples (context, warning) where <br /> - Context is the field (or dotted field path, if a sub-field) - Warning is the string warning text ||

<br />

### `ToValue`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L707-L720)

    ToValue(
        value
    )

Convert `value` to a simplified collection or basic type.

Subclasses of `Validator` should override this method when the dumped
representation of `value` is not a simple `<type>(value)` (e.g., a regex).

<br />

<br />

<br />

| Args ||
|---|---|
| `value` | An object of the same type that was returned from `Validate()`. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| An instance of a builtin type (e.g., int, str, dict, etc). By default it returns `value` unmodified. ||

<br />

### `Validate`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L1461-L1462)

    Validate(
        value, key
    )

Validate this field. Override to customize subclass behavior.

<br />

<br />

<br />

| Args ||
|---|---|
| `value` | Value to validate. |
| `key` | Name of the field being validated. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| Value if value is valid, or a valid representation of value. ||

<br />

### `__call__`

[View source](https://github.com/GoogleCloudPlatform/appengine-python-standard/tree/main/src/google/appengine/api/validation.py#L673-L675)

    __call__(
        value, key='???'
    )

Main interface to validator is call mechanism.