DHI/terracotta

getting png from singleband error: Unsupported operand type(s) for /: 'decimal.Decimal' and 'float'

Chris-Charisis opened this issue · 6 comments

I have deployed terracotta as an AWS Lambda function, connected to an RDS instance and the TIFF files were in an S3 bucket. It was working properly but suddenly it started producing this error:

`[ERROR] 2023-02-20T10:35:12.972Z 54c93dc2-0cbd-494a-8e6e-c24e3ec2a0db Exception on /singleband/afElements/soil/al/0030/200801/201412/1000/6/6/6.png [GET]
Traceback (most recent call last):

File "/tmp/terracotta/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/tmp/terracotta/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/tmp/terracotta/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/tmp/terracotta/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/tmp/terracotta/terracotta/server/singleband.py", line 120, in get_singleband
return _get_singleband_image(keys, tile_xyz)
File "/tmp/terracotta/terracotta/server/singleband.py", line 164, in _get_singleband_image
image = singleband(parsed_keys, tile_xyz=tile_xyz, **options)
File "/var/lang/lib/python3.9/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/tmp/terracotta/terracotta/handlers/singleband.py", line 43, in singleband
tile_data = xyz.get_tile_data(
File "/tmp/terracotta/terracotta/xyz.py", line 36, in get_tile_data
if not tile_exists(wgs_bounds, tile_x, tile_y, tile_z):
File "/tmp/terracotta/terracotta/xyz.py", line 52, in tile_exists
mintile = mercantile.tile(bounds[0], bounds[3], tile_z)
File "/tmp/terracotta/mercantile/init.py", line 415, in tile
x, y = _xy(lng, lat, truncate=truncate)
File "/tmp/terracotta/mercantile/init.py", line 387, in _xy
x = lng / 360.0 + 0.5
TypeError: unsupported operand type(s) for /: 'decimal.Decimal' and 'float'`

I have tried different things, even not related directly to the error, like deleting the database and recreating it, deleting and reuploading the files with different compression in terracotta-optimize (ZTSD, Deflate, no compression). Can someone help me with this one please?

Thanks for raising this. This looks like a bug in terracotta.

I assume that a miconfiguration of SQL alchemy leads to it returning Decimal objects for the bounds when we expect floats. What database flavor are you using? MySQL?

I am using MySQL

Tests are passing, so unfortunately I can't reproduce this yet. Could you post the output of pip freeze (from the same environment that's used to deploy to Lambda) so we can check if this is a version issue?

pip freeze output

affine==2.3.1
apispec==6.0.2
apispec-webframeworks==0.5.2
argcomplete==2.0.0
attrs==22.2.0
aws-xray-sdk==2.11.0
boto3==1.26.50
botocore==1.29.50
cachetools==5.2.1
certifi==2022.12.7
cfn-flip==1.3.0
charset-normalizer==3.0.1
click==8.1.3
click-plugins==1.1.1
click-spinner==0.1.10
cligj==0.7.2
durationpy==0.5
Flask==2.2.2
Flask-Cors==3.0.10
greenlet==2.0.1
hjson==3.1.0
idna==3.4
importlib-metadata==6.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
jmespath==1.0.1
kappa==0.6.0
MarkupSafe==2.1.1
marshmallow==3.19.0
mercantile==1.2.1
numpy==1.24.1
packaging==23.0
Pillow==9.4.0
placebo==0.9.0
PyMySQL==1.0.2
pyparsing==3.0.9
python-dateutil==2.8.2
python-slugify==7.0.0
PyYAML==6.0
rasterio==1.3.4
requests==2.28.2
s3transfer==0.6.0
shapely==2.0.0
six==1.16.0
snuggs==1.4.7
SQLAlchemy==1.4.46
terracotta==0.7.5
text-unidecode==1.3
toml==0.10.2
tqdm==4.64.1
troposphere==4.2.0
urllib3==1.26.14
Werkzeug==2.2.2
wrapt==1.14.1
zappa==0.56.1
zipp==3.11.0

Still cannot reproduce, even with these exact versions. So this must somehow be specific to the MySQL dialect being used?

Have you tried whether the issue persists if you use the current main branch of Terracotta?

Assume it's fixed with the new release, please re-open otherwise.