aws / aws/aws-cdk

wafv2: `CfnWebACL.JsonMatchPatternProperty.all` doesn't accept `any` value as documented

Open
#30,666 10 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-wafv2 bug effort/small jsii p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

This pertains to the Python bindings, but I believe the issue affects TypeScript as well, though to a lesser degree.

The [documentation for `JsonMatchPatternProperty.all` states](https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_wafv2/CfnWebACL.html#jsonmatchpatternproperty):

> all (Any) – Match all of the elements. See also MatchScope in the JsonBody FieldToMatch specification. You must specify either this setting or the IncludedPaths setting, but not both.

However, if I specify `all=True`, `cdk synth` fails:

```
RuntimeError: Error: Resolution error: Supplied properties not correct for "CfnWebACLProps"
rules: element 2: supplied properties not correct for "RuleProperty"
statement: supplied properties not correct for "StatementProperty"
sqliMatchStatement: supplied properties not correct for "SqliMatchStatementProperty"
fieldToMatch: supplied properties not correct for "FieldToMatchProperty"
jsonBody: supplied properties not correct for "JsonBodyProperty"
matchPattern: supplied properties not correct for "JsonMatchPatternProperty"
all: true should be an 'object'.
```

So the type hint is incorrect; a value of `Any` type is *not* legal for the `all` argument.

The example code in the documentation is:

```python
import aws_wafv2 as wafv2

# all: Any

json_match_pattern_property = wafv2.CfnWebACL.JsonMatchPatternProperty(
all=all,
included_paths=["includedPaths"]
)
```

This violates the immediately preceding text, "You must specify either this setting or the IncludedPaths setting, but not both." Specifying only `all=all` does not work; `all` is a built-in function in Python, which causes a JSII error:

```
jsii.errors.JSIIError: Cannot pass function as argument here (did you mean to call this function?):
```

It appears that I have to pass some JSII-serializable value here to indicate truthy state, such as:

```python
match_pattern=waf.CfnWebACL.JsonMatchPatternProperty(all={}),
```

This is a very unusual way to express a boolean, particularly because an empty dict is considered `False` in Python:

```python
>>> "true" if {} else "false"
'false'
>>> "true" if {"some": "value"} else "false"
'true'
>>>
```

### Expected Behavior

- I expected that a value conforming to the type hint of the `all` attribute would work.
- I expected that the example code would work.
- I expect fields for boolean options to accept boolean values.
- I expect fields taking truthy/falsey values to conform to Python's notions of truthy and falsey.

### Current Behavior

- Example code does not work.
- Boolean values are not accepted.
- Values treated as falsey by Python are treated as truthy by CDK.

### Reproduction Steps

1. Synth a stack containing a WAF with `JsonMatchPatternProperty` whose `all` value is `all`, as the example code does.
2. Observe that the synth fails

*or*

1. Synth a stack containing a WAF with `JsonMatchPatternProperty` whose `all` value is `True`.
2. Observe that the synth fails.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.147.1 (build d3695d4)

### Framework Version

2.147.1

### Node.js Version

v18.15.0

### OS

macOS Sonoma 14.5 (23F79)

### Language

Python

### Language Version

Python 3.10.7

### Other information

The [TypeScript documentation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_wafv2.CfnLoggingConfiguration.MatchPatternProperty.html#all) also says that `all?` can accept `any` type, though this is not true.

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with CfnWebACL.JsonMatchPatternProperty in Python using both the documented example and all=True, then compare the Python and TypeScript API documentation. Trace the jsii validation or serialization for the all property and confirm completion when boolean input and the documented example behave consistently during cdk synth.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python, typescript
Domain
cloud, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.