Skip to content
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

[CLI] Warn instead of throwing an error when profile config can't be validated #16813

Open
znicholasbrown opened this issue Jan 22, 2025 · 0 comments
Labels
enhancement An improvement of an existing feature

Comments

@znicholasbrown
Copy link
Contributor

Describe the current behavior

The CLI validates all profile settings before executing any command, causing operations to fail entirely if any setting is invalid - even when that setting is unrelated to the requested operation.

Many CLI commands read from and validate profile settings during their execution. However, when settings are migrated between versions, it's easy for profile configs to become outdated, leading to validation errors like this:

raceback (most recent call last):
  File "/Users/nicholas/projects/prefect/src/prefect/cli/_utilities.py", line 43, in wrapper
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/nicholas/projects/prefect/src/prefect/cli/_types.py", line 155, in sync_fn
    return asyncio.run(async_fn(*args, **kwargs))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nicholas/.pyenv/versions/3.11.7/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/nicholas/.pyenv/versions/3.11.7/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nicholas/.pyenv/versions/3.11.7/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/nicholas/projects/prefect/src/prefect/cli/cloud/__init__.py", line 567, in login
    update_current_profile(
  File "/Users/nicholas/projects/prefect/src/prefect/settings/profiles.py", line 400, in update_current_profile
    new_profile.validate_settings()
  File "/Users/nicholas/projects/prefect/src/prefect/settings/profiles.py", line 96, in validate_settings
    raise ProfileSettingsValidationError(errors)
prefect.exceptions.ProfileSettingsValidationError: [(<PREFECT_LOGGING_LEVEL: typing.Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']>, 1 validation error for literal['DEBUG','INFO','WARNING','ERROR','CRITICAL']
  Input should be 'DEBUG', 'INFO', 'WARNING', 'ERROR' or 'CRITICAL' [type=literal_error, input_value='debug', input_type=str]
    For further information visit https://errors.pydantic.dev/2.10/v/literal_error)]

In this case, I had this setting: PREFECT_LOGGING_LEVEL='debug' instead of PREFECT_LOGGING_LEVEL='DEBUG'; despite being unrelated to the command I was running (prefect cloud login), I was unable to continue until I resolved the issue in my current config.

Describe the proposed behavior

  1. When encountering invalid settings that don't affect the current command:

    • Display a human-readable warning about the invalid setting
    • Allow the command to proceed normally
      Example: "Warning: PREFECT_LOGGING_LEVEL='debug' is invalid (should be uppercase 'DEBUG'). This won't affect the current command."
  2. When encountering invalid settings that would affect the current command:

    • Display a clear error message identifying the specific invalid setting
    • Provide guidance on how to fix it
    • Example: "Error: Cannot execute 'prefect config get' - PREFECT_LOGGING_LEVEL='debug' is invalid. Please use uppercase 'DEBUG' instead."

Example Use

No response

Additional context

No response

@znicholasbrown znicholasbrown added the enhancement An improvement of an existing feature label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant