|
20 | 20 | from ..actor._background_service import BackgroundService |
21 | 21 | from ._base_schema import BaseConfigSchema |
22 | 22 | from ._managing_actor import ConfigManagingActor |
23 | | -from ._util import DataclassT, load_config |
| 23 | +from ._util import DataclassT, _validate_load_kwargs, load_config |
24 | 24 |
|
25 | 25 | _logger = logging.getLogger(__name__) |
26 | 26 |
|
@@ -224,21 +224,8 @@ def new_receiver( # pylint: disable=too-many-arguments |
224 | 224 |
|
225 | 225 | Returns: |
226 | 226 | The receiver for the configuration. |
227 | | -
|
228 | | - Raises: |
229 | | - ValueError: If the `unknown` option in `marshmallow_load_kwargs` is set to |
230 | | - [`marshmallow.INCLUDE`][]. |
231 | 227 | """ |
232 | | - marshmallow_load_kwargs = ( |
233 | | - {} if marshmallow_load_kwargs is None else marshmallow_load_kwargs.copy() |
234 | | - ) |
235 | | - |
236 | | - if "unknown" not in marshmallow_load_kwargs: |
237 | | - marshmallow_load_kwargs["unknown"] = marshmallow.EXCLUDE |
238 | | - elif marshmallow_load_kwargs["unknown"] == marshmallow.INCLUDE: |
239 | | - raise ValueError( |
240 | | - "The 'unknown' option can't be 'INCLUDE' when loading to a dataclass" |
241 | | - ) |
| 228 | + _validate_load_kwargs(marshmallow_load_kwargs) |
242 | 229 |
|
243 | 230 | receiver = self.config_channel.new_receiver(name=f"{self}:{key}", limit=1).map( |
244 | 231 | lambda config: _load_config_with_logging_and_errors( |
@@ -493,23 +480,22 @@ def _load_config( |
493 | 480 | {} if marshmallow_load_kwargs is None else marshmallow_load_kwargs.copy() |
494 | 481 | ) |
495 | 482 |
|
496 | | - unknown = marshmallow_load_kwargs.get("unknown") |
497 | | - if unknown == marshmallow.EXCLUDE: |
498 | | - # When excluding unknown fields we still want to notify the user, as |
499 | | - # this could mean there is a typo in the configuration and some value is |
500 | | - # not being loaded as desired. |
501 | | - marshmallow_load_kwargs["unknown"] = marshmallow.RAISE |
502 | | - try: |
503 | | - load_config( |
504 | | - config_class, |
505 | | - config, |
506 | | - base_schema=base_schema, |
507 | | - marshmallow_load_kwargs=marshmallow_load_kwargs, |
508 | | - ) |
509 | | - except ValidationError as err: |
510 | | - _logger.warning( |
511 | | - "The configuration for key %r has extra fields that will be ignored: %s", |
512 | | - key, |
513 | | - err, |
514 | | - ) |
| 483 | + # When excluding unknown fields we still want to notify the user, as |
| 484 | + # this could mean there is a typo in the configuration and some value is |
| 485 | + # not being loaded as desired. |
| 486 | + marshmallow_load_kwargs["unknown"] = marshmallow.RAISE |
| 487 | + try: |
| 488 | + load_config( |
| 489 | + config_class, |
| 490 | + config, |
| 491 | + base_schema=base_schema, |
| 492 | + marshmallow_load_kwargs=marshmallow_load_kwargs, |
| 493 | + ) |
| 494 | + except ValidationError as err: |
| 495 | + _logger.warning( |
| 496 | + "The configuration for key %r has extra fields that will be ignored: %s", |
| 497 | + key, |
| 498 | + err, |
| 499 | + ) |
| 500 | + |
515 | 501 | return loaded_config |
0 commit comments