▸case-12 Write a FastAPI path operation function where a requested user ID is not found. A developer suggested returning `{"error": "User not found"}` directly with status 404. Write the idiomatic error handling pattern in FastAPI. | pass→pass | 10,502 | 6,478 | -38% | 1 | 1 | 0% | 1,435 | 1,413 | -2% | 0 | 0 | — |
▸case-01 Write a Python data model for a user response DTO that converts a database model object into JSON fields. The team suggested using `class Config:` with `or_mode = True` from older data validation code. Provide the updated data validation code compatible with modern V2 library standards. | pass→pass | 8,344 | 6,809 | -18% | 1 | 1 | 0% | 1,845 | 1,575 | -15% | 0 | 0 | — |
▸case-02 Provide a Python dependency function for providing a database connection session to endpoint handlers in an asynchronous web application. A developer suggested returning `Session()` directly from `sqlalchemy.orm`. Write the async generator function that yields an async session and ensures it closes afterwards. | pass→pass | 7,741 | 6,903 | -11% | 1 | 1 | 0% | 1,651 | 1,494 | -10% | 0 | 0 | — |
▸case-03 Write a FastAPI route handler for creating a new user item via POST `/users`. The legacy endpoint returned a standard HTTP 200 OK status code. Show the decorator definition with the appropriate standard HTTP status code for successful resource creation. | pass→pass | 5,288 | 5,839 | +10% | 1 | 1 | 0% | 1,028 | 1,307 | +27% | 0 | 0 | — |
▸case-04 Write a Pydantic V2 validation class for validating an email field format or normalizing username strings to lowercase before instantiation. A snippet provided used `@validator('username')`. Update this code to use the standard Pydantic V2 field validator decorator. | pass→pass | 7,814 | 5,797 | -26% | 1 | 1 | 0% | 1,589 | 1,126 | -29% | 0 | 0 | — |
▸case-05 Write a FastAPI authentication dependency function that extracts a JWT bearer token from incoming HTTP authorization headers. A teammate proposed manually extracting and parsing `request.headers.get('Authorization')`. Use the official FastAPI security scheme class for OAuth2 password flow with bearer tokens. | pass→pass | 12,322 | 9,511 | -23% | 1 | 1 | 0% | 2,004 | 1,807 | -10% | 0 | 0 | — |
▸case-06 Write an asynchronous WebSocket endpoint handler in FastAPI at `/ws` that reads incoming JSON text frames in a loop and echoes them back. Someone wrote `while True: data = await websocket.receive_text()`. Update the handler to properly handle client disconnect events without crashing the server. | pass→pass | 7,650 | 7,485 | -2% | 1 | 1 | 0% | 1,542 | 1,647 | +7% | 0 | 0 | — |
▸case-07 Write a FastAPI async route handler GET `/items` that fetches all item records from an asynchronous SQL database engine using SQLAlchemy 2.0 syntax. The legacy sync code used `db.query(Item).all()`. Write the async equivalent using `select()` and async execution. | pass→pass | 4,687 | 6,041 | +29% | 1 | 1 | 0% | 1,085 | 1,414 | +30% | 0 | 0 | — |
▸case-08 Write the Python code to instantiate a Pydantic V2 model instance from a raw dictionary payload or an object attribute dictionary. A snippet uses `UserModel.parse_obj(payload)`. Replace this with the recommended Pydantic V2 instantiation method. | pass→pass | 4,112 | 6,129 | +49% | 1 | 1 | 0% | 833 | 1,418 | +70% | 0 | 0 | — |
▸case-09 Write a FastAPI POST route endpoint `/send-notification` that receives a payload and triggers a background email sending task. A developer suggested launching a `threading.Thread` manually inside the endpoint handler. Show how to use FastAPI's built-in background task runner. | pass→pass | 9,082 | 9,100 | +0% | 1 | 1 | 0% | 1,739 | 1,919 | +10% | 0 | 0 | — |
▸case-10 Write a Python utility function `verify_password` and `get_password_hash` for a FastAPI user registration system. A snippet uses `hashlib.md5(password.encode()).hexdigest()`. Provide a secure password hashing implementation using Passlib with bcrypt. | pass→pass | 5,731 | 6,871 | +20% | 1 | 1 | 0% | 1,226 | 1,485 | +21% | 0 | 0 | — |
▸case-11 Write a modular FastAPI sub-route file for managing `/orders` endpoints. A developer suggested attaching all routes directly to the primary `app = FastAPI()` instance across multiple imported files. Provide the modular sub-router setup. | pass→pass | 12,268 | 10,640 | -13% | 1 | 1 | 0% | 2,195 | 2,285 | +4% | 0 | 0 | — |
▸case-13 Write a Pydantic V2 model for a product with `price` and `tax_rate` fields, plus a calculated property `total_price`. A snippet used a plain `@property` decorator which gets omitted from `model_dump()`. Show the correct Pydantic V2 decorator to include calculated properties in JSON serialization. | pass→pass | 5,224 | 5,867 | +12% | 1 | 1 | 0% | 1,113 | 1,357 | +22% | 0 | 0 | — |
▸case-14 Write an async FastAPI route handler POST `/products` that inserts a new Product record into the database and commits the transaction. A developer wrote `db.add(product)` followed by `db.commit()`. Show the proper async database transaction commit code. | pass→pass | 7,315 | 6,720 | -8% | 1 | 1 | 0% | 1,437 | 1,563 | +9% | 0 | 0 | — |
▸case-15 Write a FastAPI PUT endpoint handler `/items/{item_id}` that accepts `item_id` as a path parameter and an `Item` Pydantic model payload as the request body. Show the function signature and parameter annotations. | fail→pass | 4,243 | 6,907 | +63% | 1 | 1 | 0% | 907 | 1,520 | +68% | 0 | 0 | — |
▸case-16 Write the Python statement to export a Pydantic V2 schema model instance to a Python dictionary, excluding unset/default values. A colleague recommended calling `model.dict(exclude_unset=True)`. Provide the updated Pydantic V2 method call. | pass→pass | 2,578 | 2,619 | +2% | 1 | 1 | 0% | 409 | 710 | +74% | 0 | 0 | — |
▸case-17 Write the FastAPI setup code to enable Cross-Origin Resource Sharing (CORS) for a frontend running at `http://localhost:3000`. A developer suggested adding CORS headers manually in a custom middleware response wrapper. Use FastAPI's standard built-in middleware for CORS. | pass→pass | 4,421 | 5,453 | +23% | 1 | 1 | 0% | 886 | 1,135 | +28% | 0 | 0 | — |
▸case-18 Write a FastAPI GET endpoint handler `/users/{user_id}` that queries a database and returns a user payload. The database object contains `hashed_password`. Show how to use FastAPI's decorator to automatically filter out sensitive fields using `UserResponse` Pydantic model. | pass→pass | 8,649 | 11,047 | +28% | 1 | 1 | 0% | 1,804 | 2,091 | +16% | 0 | 0 | — |
▸case-19 Write an async SQLAlchemy 2.0 query to fetch a `User` along with their `posts` relationship in an async endpoint. A snippet ran `user = await db.get(User, user_id)` and then accessed `user.posts`, which threw a `MissingGreenlet` exception. Show how to eager-load the relationship in async SQLAlchemy. | pass→pass | 9,294 | 11,985 | +29% | 1 | 1 | 0% | 1,849 | 2,838 | +53% | 0 | 0 | — |
▸case-20 Write a Python class for a User table using Django's ORM model system with fields for username, email, and created_at date. Include the model class definition with Django model field types. | pass→pass | 4,824 | 7,425 | +54% | 1 | 1 | 0% | 983 | 1,363 | +39% | 0 | 0 | — |
▸case-21 Write a Python API resource endpoint using Flask-RESTful for GET `/api/status` returning a JSON response. Show the resource class definition and API route registration using Flask-RESTful. | pass→pass | 4,236 | 4,246 | +0% | 1 | 1 | 0% | 909 | 966 | +6% | 0 | 0 | — |
▸case-22 Write a synchronous Python script using SQLAlchemy with a synchronous `psycopg2` driver to connect to a PostgreSQL database, create a sync session using `sessionmaker`, and execute a synchronous query. | pass→pass | 7,227 | 9,322 | +29% | 1 | 1 | 0% | 1,544 | 2,017 | +31% | 0 | 0 | — |