Closed JohannesKoenigTMH closed 1 year ago
Description: When calling deregister_resource on a mocked lake formation client you get a KeyError which does not conform to the AWS docs. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lakeformation/client/deregister_resource.html I expect the error to be client.exceptions.EntityNotFoundException.
client.exceptions.EntityNotFoundException
Code to reproduce the error:
import pytest import boto3 from moto import mock_lakeformation def test_deregister_broken(): with mock_lakeformation(): client = boto3.client("lakeformation") # pyright: ignore[reportUnknownMemberType] resource_arn = "unknown_resource" with pytest.raises(client.exceptions.EntityNotFoundException): client.deregister_resource(ResourceArn=resource_arn)
Used package versions: moto=4.2.8 boto3=1.28.84 botocore=1.31.84
../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/client.py:535: in _api_call return self._make_api_call(operation_name, kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/client.py:963: in _make_api_call http, parsed_response = self._make_request( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/client.py:986: in _make_request return self._endpoint.make_request(operation_model, request_dict) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/endpoint.py:119: in make_request return self._send_request(request_dict, operation_model) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/endpoint.py:202: in _send_request while self._needs_retry( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/endpoint.py:354: in _needs_retry responses = self._event_emitter.emit( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:412: in emit return self._emitter.emit(aliased_event_name, **kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:256: in emit return self._emit(event_name, kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:239: in _emit response = handler(**kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:207: in __call__ if self._checker(**checker_kwargs): ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:284: in __call__ should_retry = self._should_retry( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:307: in _should_retry return self._checker( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:363: in __call__ checker_response = checker( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:247: in __call__ return self._check_caught_exception( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/retryhandler.py:416: in _check_caught_exception raise caught_exception ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/endpoint.py:278: in _do_get_response responses = self._event_emitter.emit(event_name, request=request) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:412: in emit return self._emitter.emit(aliased_event_name, **kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:256: in emit return self._emit(event_name, kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/botocore/hooks.py:239: in _emit response = handler(**kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/core/botocore_stubber.py:61: in __call__ status, headers, body = response_callback( ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/core/responses.py:245: in dispatch return cls()._dispatch(*args, **kwargs) ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/core/responses.py:446: in _dispatch return self.call_action() ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/core/responses.py:540: in call_action response = method() ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/lakeformation/responses.py:29: in deregister_resource self.lakeformation_backend.deregister_resource(resource_arn=resource_arn) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <moto.lakeformation.models.LakeFormationBackend object at 0x108903d10>, resource_arn = 'unknown_resource' def deregister_resource(self, resource_arn: str) -> None: > del self.resources[resource_arn] E KeyError: 'unknown_resource' ../../../Library/Caches/pypoetry/virtualenvs/info-layer-api-mTPfcUck-py3.11/lib/python3.11/site-packages/moto/lakeformation/models.py:59: KeyError
Hi @JohannesKoenigTMH, thanks for raising this, and welcome to Moto!
I'll raise a PR shortly to add the correct validation here.
Description: When calling deregister_resource on a mocked lake formation client you get a KeyError which does not conform to the AWS docs. https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lakeformation/client/deregister_resource.html I expect the error to be
client.exceptions.EntityNotFoundException
.Code to reproduce the error:
Used package versions: moto=4.2.8 boto3=1.28.84 botocore=1.31.84
Stack trace: