Null category handling - API crashes when serializing transactions with null categories #81

Closed
opened 2025-12-28 23:25:26 +01:00 by adam · 4 comments
Owner

Originally created by @SerafimPikalov on GitHub (Dec 7, 2025).

When a transaction has no category assigned (category=None), the API serializer crashes with an AttributeError when trying to serialize the transaction.

Steps to Reproduce:

  1. Create a transaction via API without a category field, or set category to null
  2. Attempt to retrieve the transaction via GET request to /api/transactions/{id}/
  3. API returns 500 error

Expected Behavior:
Transactions without categories should serialize successfully, returning category: null in the JSON response.

Actual Behavior:
API crashes with AttributeError: 'NoneType' object has no attribute 'id' when trying to access value.id on a None category.

Originally created by @SerafimPikalov on GitHub (Dec 7, 2025). When a transaction has no category assigned (`category=None`), the API serializer crashes with an `AttributeError` when trying to serialize the transaction. Steps to Reproduce: 1. Create a transaction via API without a category field, or set category to `null` 2. Attempt to retrieve the transaction via GET request to `/api/transactions/{id}/` 3. API returns 500 error Expected Behavior: Transactions without categories should serialize successfully, returning `category: null` in the JSON response. Actual Behavior: API crashes with `AttributeError: 'NoneType' object has no attribute 'id'` when trying to access `value.id` on a None category.
adam closed this issue 2025-12-28 23:25:26 +01:00
Author
Owner

@SerafimPikalov commented on GitHub (Dec 7, 2025):

Pull request to fix it: https://github.com/eitchtee/WYGIWYH/pull/428
Solution could be questionable because change validation shems, but works for me

@SerafimPikalov commented on GitHub (Dec 7, 2025): Pull request to fix it: https://github.com/eitchtee/WYGIWYH/pull/428 Solution could be questionable because change validation shems, but works for me
Author
Owner

@eitchtee commented on GitHub (Dec 7, 2025):

Thank you for the report and the fix, but I can't seem to reproduce this locally or on a production environment.

Setting category to null raises a 400 error, which makes sense considering the schema, but could probably be changed since categories are indeed nullable.

And GETting a transaction with a null category just works.

Do you have some reproducible curls commands (or something else)?

@eitchtee commented on GitHub (Dec 7, 2025): Thank you for the report and the fix, but I can't seem to reproduce this locally or on a production environment. Setting category to null raises a 400 error, which makes sense considering the schema, but could probably be changed since categories are indeed nullable. And GETting a transaction with a null category just works. Do you have some reproducible curls commands (or something else)?
Author
Owner

@SerafimPikalov commented on GitHub (Dec 7, 2025):

I’m out of code right now and can’t test it, but it should be pretty close to these ones:

  1. First, create a transaction without a category:
    curl -X POST http://127.0.0.1:9005/api/transactions/
    -u "login:pass"
    -H "Content-Type: application/json"
    -d '{
    "account_id": 1,
    "date": "2025-02-03",
    "amount": "123.45",
    "description": "Example purchase",
    "type": "EX",
    "is_paid": true
    }'

  2. Set prexisted category:
    curl -X PATCH http://127.0.0.1:9005/api/transactions/1234/
    -u "login:pass"
    -H "Content-Type: application/json"
    -d '{"category": "Groceries"}'

@SerafimPikalov commented on GitHub (Dec 7, 2025): I’m out of code right now and can’t test it, but it should be pretty close to these ones: 1. First, create a transaction without a category: curl -X POST http://127.0.0.1:9005/api/transactions/ \ -u "login:pass" \ -H "Content-Type: application/json" \ -d '{ "account_id": 1, "date": "2025-02-03", "amount": "123.45", "description": "Example purchase", "type": "EX", "is_paid": true }' 2. Set prexisted category: curl -X PATCH http://127.0.0.1:9005/api/transactions/1234/ \ -u "login:pass" \ -H "Content-Type: application/json" \ -d '{"category": "Groceries"}'
Author
Owner

@eitchtee commented on GitHub (Dec 7, 2025):

Yeah, no luck on my side.

Image Image

However the fix is solid and shouldn't cause any problems.

@eitchtee commented on GitHub (Dec 7, 2025): Yeah, no luck on my side. <img width="1686" height="864" alt="Image" src="https://github.com/user-attachments/assets/3968d14d-eb9b-4c3f-a930-e45a19bd99d0" /> <img width="1679" height="862" alt="Image" src="https://github.com/user-attachments/assets/a66fc2fc-0616-48a5-a9f1-0391d9199b2a" /> However the fix is solid and shouldn't cause any problems.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WYGIWYH#81