DHI / terracotta

A light-weight, versatile XYZ tile server, built with Flask and Rasterio :earth_africa:

Home Page:https://terracotta-python.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NoSuchTableError: key_names on zappa deploy

angelosnm opened this issue · comments

I have created an .sqlite file by following the documentation guide and moved it to the S3 bucket. Then, I'm trying to deploy the AWS Lambda function with zappa and I'm getting the below error.

It seems that the table "key_names" does not exist but instead there is a table named "keys".

Oh no! An error occurred! :(

==============

Traceback (most recent call last):
  File "/home/ubuntu/terracotta/terracotta/drivers/relational_meta_store.py", line 49, in convert_exceptions
    yield
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/ubuntu/terracotta/terracotta/drivers/relational_meta_store.py", line 276, in get_keys
    keys_table = sqla.Table('key_names', self.sqla_metadata, autoload_with=self.sqla_engine)
  File "<string>", line 2, in __new__
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 375, in warned
    return fn(*args, **kwargs)
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 619, in __new__
    metadata._remove_table(name, schema)
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 614, in __new__
    table._init(name, metadata, *args, **kw)
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 689, in _init
    self._autoload(
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 724, in _autoload
    conn_insp.reflect_table(
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/sqlalchemy/engine/reflection.py", line 789, in reflect_table
    raise exc.NoSuchTableError(table_name)
sqlalchemy.exc.NoSuchTableError: key_names

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/terracotta/zappa_settings_callback.py", line 36, in check_integrity
    some_dataset = next(iter(driver.get_datasets().keys()))
  File "/home/ubuntu/terracotta/terracotta/drivers/base_classes.py", line 43, in inner
    return fun(self, *args, **kwargs)
  File "/home/ubuntu/terracotta/terracotta/drivers/terracotta_driver.py", line 132, in get_datasets
    where=self._standardize_multi_value_keys(where, requires_all_keys=False),
  File "/home/ubuntu/terracotta/terracotta/drivers/terracotta_driver.py", line 318, in _standardize_multi_value_keys
    return self._ensure_keys_as_dict(keys, requires_all_keys)
  File "/home/ubuntu/terracotta/terracotta/drivers/terracotta_driver.py", line 341, in _ensure_keys_as_dict
    unknown_keys = set(keys) - set(self.key_names)
  File "/home/ubuntu/terracotta/terracotta/drivers/terracotta_driver.py", line 59, in key_names
    return self.meta_store.key_names
  File "/home/ubuntu/terracotta/terracotta/drivers/relational_meta_store.py", line 289, in key_names
    self._db_keys = self.get_keys()
  File "/home/ubuntu/terracotta/terracotta/drivers/base_classes.py", line 43, in inner
    return fun(self, *args, **kwargs)
  File "/usr/lib/python3.9/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/usr/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/ubuntu/terracotta/terracotta/drivers/relational_meta_store.py", line 51, in convert_exceptions
    raise exceptions.InvalidDatabaseError(error_message) from exception
terracotta.exceptions.InvalidDatabaseError: Could not retrieve keys from database

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/zappa/cli.py", line 3044, in handle
    sys.exit(cli.handle())
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/zappa/cli.py", line 519, in handle
    self.dispatch_command(self.command, stage)
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/zappa/cli.py", line 557, in dispatch_command
    self.callback("settings")
  File "/home/ubuntu/envs/tc-deploy/lib/python3.9/site-packages/zappa/cli.py", line 2171, in callback
    cb_func(self)  # Call the function passing self
  File "/home/ubuntu/terracotta/zappa_settings_callback.py", line 38, in check_integrity
    raise RuntimeError(
RuntimeError: Error while connecting to remote database. Please double-check your AWS environment variables, and make sure your machine has access to the remote Terracotta database.

==============

Need help? Found a bug? Let us know! :D
File bug reports on GitHub here: https://github.com/Zappa/Zappa
And join our Slack channel here: https://zappateam.slack.com
Love!,
 ~ Team Zappa!

Please make sure that the terracotta version that is deployed is the same that was used to create your database. Sounds like you are using current master for the former and the last release for the latter.

yeap, this was the issue. The databased created using 0.7.5 whereas I was using a 0.7.6 dev version to deploy the lambda function. Thanks!