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

[2023-04-30 17:46:44,787] ERROR in app: Exception on /api/message_groups [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.10/site-packages/flask_cors/extension.py", line 165, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  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.