Resource type handler_update fails to delete the right model version

Ouverte
#1,090 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
1/5
Temps estimé
Moins d'une heure
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
python
Domaine
testing

Piste de recherche

Commencez dans src/rpdk/core/contract/suite/resource/handler_update.py, au niveau de updated_resource, et suivez quel modèle est conservé pendant la mise à jour réussie puis lors du nettoyage final. Exécutez la suite de contrats du type de ressource concernée et confirmez que le nettoyage utilise le modèle renvoyé par la mise à jour, y compris pour les ressources qui imposent un verrouillage optimiste par version.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

The updated_resource in handler_update resource type test suite is wrongly deleting the created model in its finally section instead of the potentially updated model.

My resource type is maintaining a Version field on the server with optimistic locking to avoid accidental overwrite of the resource. Upon a successful update, the version is auto-incremented and the new version is returned to the client. The client specifies the version in the If-Match header of the HTTP request, and the server allows the mutation only if the version stored is the same.

In the following function:

def updated_resource(resource_client):
    create_request = input_model = resource_client.generate_create_example()
    model = {}
    try:
        _status, response, _error = resource_client.call_and_assert(
            Action.CREATE, OperationStatus.SUCCESS, create_request
        )
        created_model = model = response["resourceModel"]
        test_input_equals_output(resource_client, input_model, created_model)

        update_request = resource_client.generate_update_example(created_model)

        _status, response, _error = resource_client.call_and_assert(
            Action.UPDATE, OperationStatus.SUCCESS, update_request, created_model
        )
        updated_model = response["resourceModel"]
        test_input_equals_output(resource_client, update_request, updated_model)

        # flake8: noqa: B950
        # pylint: disable=C0301
        yield create_request, created_model, update_request, updated_model, update_request
    finally:
        resource_client.call_and_assert(Action.DELETE, OperationStatus.SUCCESS, model)

The following call to update:

       _status, response, _error = resource_client.call_and_assert(
            Action.UPDATE, OperationStatus.SUCCESS, update_request, created_model
        )
        updated_model = response["resourceModel"]

increments the resource version but the delete is made on the original model, which in my case, has the previous version, and thus fails:

     finally:
        resource_client.call_and_assert(Action.DELETE, OperationStatus.SUCCESS, model)

A potential fix, is to update the model upon successful update:

       _status, response, _error = resource_client.call_and_assert(
            Action.UPDATE, OperationStatus.SUCCESS, update_request, created_model
        )
        model = updated_model = response["resourceModel"]

When trying to delete the resource in the finally section now, the right model is provided

Langage dominant
Python
Étoiles
336
Forks
173
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de aws-cloudformation/cloudformation-cli

Toutes les issues de aws-cloudformation/cloudformation-cli

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.