Bug: S3RecordModel drops lifecycleEventData and replicationEventData

Abierto Apto para principiantes
#8,800 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
82/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
aws, python
Área
backend, data

Línea de trabajo

Empieza leyendo S3RecordModel y los campos de datos de eventos adyacentes; después, inspecciona tests/events/s3EventLifecycleTransition.json y las pruebas del parser para registros de S3. Añade cobertura para conservar ambos campos de datos del evento, incluido un ejemplo de replicación adecuado. El trabajo estará terminado cuando el análisis de eventos S3 y S3-to-SQS conserve los datos y pasen las pruebas relevantes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Expected Behaviour

S3RecordModel keeps lifecycleEventData and replicationEventData when S3 sends them, the same way it keeps glacierEventData and intelligentTieringEventData. They hold the main detail of those events, like the storage class an object moved to or why a replication failed. The event message structure docs list both, and there are samples for Lifecycle transition and replication events.

Current Behaviour

The model doesn't declare either key, and Pydantic ignores keys it doesn't know, so these events parse without an error but the data isn't on the parsed record. The repo's own tests/events/s3EventLifecycleTransition.json has lifecycleEventData, and it's gone after parsing. S3SqsEventNotificationModel reuses S3Model, so S3 to SQS events lose it too.

The TypeScript parser added both in aws-powertools/powertools-lambda-typescript#5924.

Code snippet
import json

from aws_lambda_powertools.utilities.parser import parse
from aws_lambda_powertools.utilities.parser.models import S3Model

with open("tests/events/s3EventLifecycleTransition.json") as f:
    event = json.load(f)

print("in event:", "lifecycleEventData" in event["Records"][0])
record = parse(event=event, model=S3Model).Records[0]
print("on parsed record:", "lifecycleEventData" in record.model_dump())
in event: True
on parsed record: False
Possible Solution

Add both as optional fields next to intelligentTieringEventData, with Field(description=...) like the rest of the model:

class S3EventRecordLifecycleTransitionEventData(BaseModel):
    destinationStorageClass: str


class S3EventRecordLifecycleEventData(BaseModel):
    transitionEventData: S3EventRecordLifecycleTransitionEventData


class S3EventRecordReplicationEventData(BaseModel):
    replicationRuleId: str | None = None
    destinationBucket: str | None = None
    s3Operation: str | None = None
    requestTime: str | None = None
    failureReason: str | None = None


# In S3RecordModel
lifecycleEventData: S3EventRecordLifecycleEventData | None = None
replicationEventData: S3EventRecordReplicationEventData | None = None

Every replication field is optional because the docs only show the failed replication event, the same call the TypeScript fix made. This only adds fields, so nothing that parses today changes.

I'm happy to send a PR with tests and a replication fixture if that sounds good.

Steps to Reproduce

Run the snippet above from the repo root. The replication sample from the docs page loses replicationEventData the same way.

Powertools for AWS Lambda (Python) version

3.40.0

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Lenguaje dominante
Python
Estrellas
3.3k
Forks
511
Merge medio
3 d 8 h
PR fusionados (30 d)
103

Preparar el entorno

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 aws-powertools/powertools-lambda-python

Todos los issues de aws-powertools/powertools-lambda-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.