Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

(V3) Verifying a contract with a missing content field is always successful when it should error

Abierto
#1,103 5 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 2 días

@JP-Ellis ya está trabajando en esto.

Desde el 6/10/2025.

  • #61 de @Endika — fusionado
  • #547 de @Endika — fusionado

Evaluación

Este issue todavía no se ha evaluado.

Descripción

area:core type:bug
Have you read the Contributing Guidelines on issues?
Prerequisites
  • I'm using the latest version of pact-python.
  • I have read the console error message carefully (if applicable).
Description

I have two pacts, one is incorrectly setting the content thus:

  "contents": {
      "Payload": "exists"
  }

The other is correctly setting the content thus:

  "contents": {
      "content": {
          "Payload": "exists"
      },
      "contentType": "application/json",
      "encoded": false
  }

When verifying with content that does not match, I expect both pacts to fail to verify. However, the first pact with the incorrect json verifies successfully and there is no error or warning that anything is wrong:

Verifying a pact between my-consumer and my-provider

  This works as expected when verifying my-provider (0s loading, 8ms verification)
     Given When reading a message from the SQS queue
    generates a message which
      includes metadata
        "contentType" with value "application/json" (OK)
      has a matching body (FAILED)


Verifying a pact between other-consumer and my-provider

  This is silently ignored while verifying my-provider (0s loading, 6ms verification)
     Given When reading a message from the SQS queue
    generates a message which
      has a matching body (OK)

I'll see if I can get approval to share a producible demo repo, but for now the pacts are:

pact-missing-contents.json

{
    "consumer": {
        "name": "other-consumer"
    },
    "provider": {
        "name": "my-provider"
    },
    "interactions": [
        {
            "_id": "1",
            "type": "Asynchronous/Messages",
            "description": "This is silently ignored while verifying my-provider",
            "providerStates": [
                {
                    "name": "When reading a message from the SQS queue"
                }
            ],
            "contents": {
                "Payload": "exists"
            }
        }
    ],
    "metadata": {
        "pactRust": {
            "ffi": "0.4.22",
            "models": "1.2.3"
        },
        "pactSpecification": {
            "version": "4.0"
        }
    }
}
pact-with-contents.json

{
    "consumer": {
        "name": "my-consumer"
    },
    "provider": {
        "name": "my-provider"
    },
    "interactions": [
        {
            "_id": "2",
            "type": "Asynchronous/Messages",
            "description": "This works as expected when verifying my-provider",
            "providerStates": [
                {
                    "name": "When reading a message from the SQS queue"
                }
            ],
            "contents": {
                "content": {
                    "Payload": "exists"
                },
                "contentType": "application/json",
                "encoded": false
            }
        }
    ],
    "metadata": {
        "pactRust": {
            "ffi": "0.4.22",
            "models": "1.2.3"
        },
        "pactSpecification": {
            "version": "4.0"
        }
    }
}

And here's an idea of running the verification. I actually use a whole pytest setup with fixtures, but for brevity this ought to be able to reproduce the issue. Again, hopefully I'll be able to share a repo soon.

verify.py

def run_message_handler(name: str, metadata: dict[str, Any] | None) -> Message:
    """This should fail to match due to missing Payload field for **both** pacts"""
    return Message(contents=b"{}", content_type="application/json", metadata=None)

verifier = Verifier("my-provider")
pact_dir = Path(file).parent / "pacts"
verifier = verifier.add_source(pact_dir).set_error_on_empty_pact()

verifier.message_handler(run_message_handler).verify()

*caveat to "I'm using the latest version": I'm using the latest version available on pypi, version 2.3.1 (as opposed to 2.3.2 available via github releases)

Reproducible demo

No response

Steps to reproduce

step 1: copy the two pact jsons and place them in separate files in a pacts/ directory
step 2: verify the pacts using pact v3, see verify.py for an example

Expected behavior

it should fail with an error due to missing "content" and/or "contentType" but it does not.

You can also enable logging (before step 3) and confirm there is no warning or error logged.

Actual behavior

"other-consumer" pact (pact-missing-contents.json) is verified successfully.
"my-consumer" pact (pact-with-contents.json) fails to verify (due to the mismatched content, as expected).

Your environment
  • Public source code: no
  • Is this a consumer or provider issue? Do you have information about the other side?: provider
  • Pact Python version used: pip list | grep pact: pact-python 2.3.1
  • Information about your Pact broker (version, hosted where, pactflow, ...): N/A
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS, macOS Ventura): Debian GNU/Linux 12 (bookworm)
Self-service
  • I'd be willing to fix this bug myself.
Lenguaje dominante
Python
Estrellas
685
Forks
147
Merge medio
4 d 8 h
PR fusionados (30 d)
14

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pact-foundation/pact-python

Todos los issues de pact-foundation/pact-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.