0

Following the documentation for flask_dynamo you are instructed to set up the table configuration as follows:

# app.py

from flask import Flask
from flask_dynamo import Dynamo

app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [
    {
         TableName='users',
         KeySchema=[dict(AttributeName='username', KeyType='HASH')],
         AttributeDefinitions=[dict(AttributeName='username', AttributeType='S')],
         ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }, {
         TableName='groups',
         KeySchema=[dict(AttributeName='name', KeyType='HASH')],
         AttributeDefinitions=[dict(AttributeName='name', AttributeType='S')],
         ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }
]

dynamo = Dynamo(app)

Here is my code, which for the moment is just mostly a copy and paste before adjusting the tables to actual tables I'll be using:

""" Initialise the app """
app = Flask(__name__)
app.config.from_object(Config)
dynamo = Dynamo(app)
app.config['DYNAMO_TABLES'] = [
    {
         TableName='users',
         KeySchema=[dict(AttributeName='username', KeyType='HASH')],
         AttributeDefinitions=[dict(AttributeName='username', AttributeType='S')],
         ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }, {
         TableName='groups',
         KeySchema=[dict(AttributeName='name', KeyType='HASH')],
         AttributeDefinitions=[dict(AttributeName='name', AttributeType='S')],
         ProvisionedThroughput=dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }
]

env = "Development"

However Visual Studio code is already picking up a syntax error as follows:

invalid syntax (<unknown>, line 19)pylint(syntax-error)

The red squiggly is showing up on the '=' sign here:

 TableName='users',

No idea why this is occuring?

davidism
  • 121,510
  • 29
  • 395
  • 339
JamesMatson
  • 2,522
  • 2
  • 37
  • 86
  • You use colons, not equal signs, to separate the keys & values of a dict. – jasonharper Jan 13 '20 at 23:23
  • Thanks, so the documentation is incorrect? – JamesMatson Jan 13 '20 at 23:25
  • Incorrect, or taken out of context (you do use equal signs for passing keyword arguments to a function, for example). Where exactly did you see this code? – jasonharper Jan 13 '20 at 23:27
  • Here -> https://flask-dynamo.readthedocs.io/en/latest/quickstart.html#set-environment-variables and now that i've changed to ':' I'm getting undefined variable for TableName, KeySchema and so on. Clearly I've missed something, just not sure what. – JamesMatson Jan 13 '20 at 23:31
  • Looks like others have had the same issue, I just came across https://stackoverflow.com/questions/55094922/example-for-flask-dynamodb-that-is-throwing-an-exception-for-syntax-error which reports a similar issue and what appears to be the correct way to instantiate the tables collection using dict. – JamesMatson Jan 13 '20 at 23:37

1 Answers1

0

The documentation is using an invalid python syntax.

This is the correct syntax:

app.config['DYNAMO_TABLES'] = [
    {
         'TableName' : 'users',
         'KeySchema' : [dict(AttributeName='username', KeyType='HASH')],
         'AttributeDefinitions' : [dict(AttributeName='username', AttributeType='S')],
         'ProvisionedThroughput' : dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }, {
         'TableName' : 'groups',
         'KeySchema' : [dict(AttributeName='name', KeyType='HASH')],
         'AttributeDefinitions' : [dict(AttributeName='name', AttributeType='S')],
         'ProvisionedThroughput ' : dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
    }
 ]
J.F.
  • 13,927
  • 9
  • 27
  • 65