Home > Enterprise >  Python ValueError: max() arg is an empty sequence when deploying to heroku
Python ValueError: max() arg is an empty sequence when deploying to heroku

Time:02-16

I'm using the following code to find the newest file in the list:

db_file_list = glob.glob('C:\\Users\\atammaro\\Desktop\\Stefanini\\*.db')
latest_db = max(db_file_list, key=os.path.getctime)    

Im getting the following error: ValueError: max() arg is an empty sequence

Any suggestions?

CodePudding user response:

There is no such directory in Heroku container, so your glob.glob(...) returns [], then you pass it to max(...), which can't pick maximum value from an empty list, so it raises ValueError

CodePudding user response:

As the path 'C:\\Users\\atammaro\\Desktop\\Stefanini\\*.db' doesn't exist in the Heroku environment - the glob.glob function returns an empty list. You pass that empty list to the max function which cannot pick a maximum value from an empty list and therefore raises a ValueError.

SQLite3 is a great DB for development, however Heroku's dynos don't have a filesystem that persists across deploys, and therefore a file-based database like SQLite3 isn't going work here.

Heroku has a Postgres offering that will suit - with a free tier and a basic tier that are good for small projects. The biggest benefit over SQLite is that you get backups that you wouldn't get otherwise (plus all the other Postgres features).

There's a guide to updating your settings.py to use Postgres here.

  • Related