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

Deprecate status_code and headers argument to ValidationError #336

Closed
sloria opened this issue Dec 24, 2018 · 0 comments

Comments

@sloria
Copy link
Member

commented Dec 24, 2018

As an incremental step towards #327, raise a deprecation warning when status_code is passed to ValidationError.

@sloria sloria added this to the 4.2.0 milestone Dec 24, 2018

@sloria sloria changed the title Deprecate status_code Deprecate status_code and headers argument to ValidationError Dec 24, 2018

@sloria sloria self-assigned this Dec 24, 2018

sloria added a commit that referenced this issue Dec 24, 2018

Deprecate status and headers params of ValidationErrors
* `status` and `headers` kwargs are deprecated (close #336)
* Add `error_status_code` and `error_headers`:
  See #327 (comment)

```python
def validate_foo(val):  # Before
    ...
    raise ValidationError("Error!", status_code=400)

@use_args({"foo": fields.Str(validate=validate_foo)})
def my_view(args):
    ...

def validate_foo(val):  # After
    ...
    raise ValidationError("Error!")

@use_args(
    {"foo": fields.Str(validate=validate_foo)},
    error_status_code=400
)
def my_view(args):
    ...
```

* error_handler functions and handle_error methods now take
  error_status_code and error_headers arguments. Backwards
  compatibility was maintained by checking the the number of
  arguments in the signatures.

```python
@parser.error_handler
def handle_error(error, req):  # Before
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, req, status_code, headers):  # After
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, **kwargs):  # Also works
    raise CustomError(error.messages)
```

sloria added a commit that referenced this issue Dec 25, 2018

Deprecate status and headers params of ValidationErrors
* `status` and `headers` kwargs are deprecated (close #336)
* Add `error_status_code` and `error_headers`:
  See #327 (comment)

```python
def validate_foo(val):  # Before
    ...
    raise ValidationError("Error!", status_code=400)

@use_args({"foo": fields.Str(validate=validate_foo)})
def my_view(args):
    ...

def validate_foo(val):  # After
    ...
    raise ValidationError("Error!")

@use_args(
    {"foo": fields.Str(validate=validate_foo)},
    error_status_code=400
)
def my_view(args):
    ...
```

* error_handler functions and handle_error methods now take
  error_status_code and error_headers arguments. Backwards
  compatibility was maintained by checking the the number of
  arguments in the signatures.

```python
@parser.error_handler
def handle_error(error, req):  # Before
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, req, status_code, headers):  # After
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, **kwargs):  # Also works
    raise CustomError(error.messages)
```

sloria added a commit that referenced this issue Dec 25, 2018

Deprecate status and headers params of ValidationErrors
* `status` and `headers` kwargs are deprecated (close #336)
* Add `error_status_code` and `error_headers`:
  See #327 (comment)

```python
def validate_foo(val):  # Before
    ...
    raise ValidationError("Error!", status_code=400)

@use_args({"foo": fields.Str(validate=validate_foo)})
def my_view(args):
    ...

def validate_foo(val):  # After
    ...
    raise ValidationError("Error!")

@use_args(
    {"foo": fields.Str(validate=validate_foo)},
    error_status_code=400
)
def my_view(args):
    ...
```

* error_handler functions and handle_error methods now take
  error_status_code and error_headers arguments. Backwards
  compatibility was maintained by checking the the number of
  arguments in the signatures.

```python
@parser.error_handler
def handle_error(error, req):  # Before
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, req, status_code, headers):  # After
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, **kwargs):  # Also works
    raise CustomError(error.messages)
```

sloria added a commit that referenced this issue Dec 25, 2018

Deprecate status and headers params of ValidationErrors
* `status` and `headers` kwargs are deprecated (close #336)
* Add `error_status_code` and `error_headers`:
  See #327 (comment)

```python
def validate_foo(val):  # Before
    ...
    raise ValidationError("Error!", status_code=400)

@use_args({"foo": fields.Str(validate=validate_foo)})
def my_view(args):
    ...

def validate_foo(val):  # After
    ...
    raise ValidationError("Error!")

@use_args(
    {"foo": fields.Str(validate=validate_foo)},
    error_status_code=400
)
def my_view(args):
    ...
```

* error_handler functions and handle_error methods now take
  error_status_code and error_headers arguments. Backwards
  compatibility was maintained by checking the the number of
  arguments in the signatures.

```python
@parser.error_handler
def handle_error(error, req):  # Before
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, req, status_code, headers):  # After
    raise CustomError(error.messages)

@parser.error_handler
def handle_error(error, **kwargs):  # Also works
    raise CustomError(error.messages)
```

@sloria sloria closed this in #338 Dec 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.