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

readOnlyProperties is optional, but accessed naively and can throw KeyError #3140

Closed
parsnips opened this issue Apr 11, 2024 · 1 comment
Closed

Comments

@parsnips
Copy link
Contributor

parsnips commented Apr 11, 2024

CloudFormation Lint Version

0.86.2

What operating system are you using?

mac

Describe the bug

using a cloudformation registry schema with -s option. Our resource has no readOnlyProperties and when validating the schema would throw a KeyError:

KeyError: 'readOnlyProperties'
1:1:                E0002     Unknown exception while processing rule E1019: Traceback (most recent call last):
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/__init__.py", line 322, in run_check
    return check(*args)
           ^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/__init__.py", line 46, in wrapper
    results = match_function(self, filename, cfn, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/__init__.py", line 204, in matchall
    return self.match(cfn)  # pylint: disable=E1102
           ^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/functions/Sub.py", line 176, in match
    matches.extend(self._test_string(cfn, sub_value_obj, {}, tree))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/functions/Sub.py", line 28, in _test_string
    self._test_parameter(string_param, cfn, parameters, tree)
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/rules/functions/Sub.py", line 115, in _test_parameter
    get_atts = cfn.get_valid_getatts()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/_bazel_mparsons/96ffd9bf0db81d44b013357bf9794629/sandbox/darwin-sandbox/16527/execroot/core/bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/infra/ci/linter/linter.runfiles/pip_cfn_lint/site-packages/cfnlint/template/template.py", line 426, in get_valid_getatts
    for ro_property in schema["readOnlyProperties"]:
                       ~~~~~~^^^^^^^^^^^^^^^^^^^^^^

However if you define this as a key with an empty list, it will throw a validation error:

Resource schema is invalid: [] is too short

Failed validating 'minItems' in schema['properties']['readOnlyProperties']:
    {'items': {'format': 'json-pointer', 'type': 'string'},
     'minItems': 1,
     'type': 'array'}

On instance['readOnlyProperties']:
    []

Expected behavior

Not throw a key error.

Reproduction template

Properties:
  AwsStatesLanguage:
    StartAt: Pass
    States:
      Pass:
        End: true
        Type: Pass
  Id: bfc2f774-007a-45a9-a91d-12c81f9cacdc
  Name: DeleteUserWorkflow
Type: Twisp::Database::Workflow

See attached schema.

schema.json

@kddejong
Copy link
Contributor

Your PR has been merged and released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants