Week 5 - UnboundLocalError: local variable 'ddb' referenced before assignment

Error

[2023-04-30 17:46:44,787] ERROR in app: Exception on /api/message_groups [GET]
Traceback (most recent call last):
    ...
  File "/backend-flask/app.py", line 209, in data_message_groups
    model = MessageGroup.run(cognito_user_id=cognito_user_id)
  File "/backend-flask/services/message_group.py", line 22, in run
    dynamodb = ddb.client()
UnboundLocalError: local variable 'ddb' referenced before assignment
192.168.250.72 - - [30/Apr/2023 17:46:44] "GET /api/message_groups HTTP/1.1" 500 -

Solution

  • UnboundLocalError : local variable 'ddb' referenced before assignment

    • This error simply means that ddb has not assigned any value. Hence, an empty variable, or undefined.

    • Find in which line the variable in question appears for the first time, and either give it a value, change the name or remove it.