aiondemand / AIOD-rest-api

A containerized application using FastAPI and SQLAlchemy connected to a MySQL database.
MIT License
10 stars 7 forks source link

Internal error raised upon request to count platforms with `detailed` set to true #311

Open jsmatias opened 2 months ago

jsmatias commented 2 months ago

The API raises a 500 Error: internal server error when a get request is made to counts of platforms with the detailed parameter is set to True: /counts/platforms/v1?detailed=true

How to reproduce it

> curl -X 'GET' 'http://localhost/counts/platforms/v1?detailed=true'
{"detail":"Unexpected exception while processing your request. Please contact the maintainers: type object 'Platform' has no attribute 'platform'"}

Cause When the detailed parameter set to True the API queries the DB to fetch the number of assets for each platform listed in the DB. Thus, this error occurs because platform has no field platform to be filtered from.

detailed=false -> returns a int

> curl -X 'GET' 'http://localhost/counts/datasets/v1?detailed=false' 
10000

detailed=true -> returns a json

> curl -X 'GET' 'http://localhost/counts/datasets/v1?detailed=true' 
{
  "openml": 5069,
  "zenodo": 75799
}

detailed=false -> returns a int

> curl -X 'GET' 'http://localhost/counts/platforms/v1?detailed=false'
7

detailed=true

> curl -X 'GET' 'http://localhost/counts/platforms/v1?detailed=true'
{"detail":"Unexpected exception while processing your request. Please contact the maintainers: type object 'Platform' has no attribute 'platform'"}

Suggested solution Add a condition to return the number of platforms for aiod, in case the platform field is not present in the asset. Ex.:

> curl -X 'GET' 'http://localhost/counts/platforms/v1?detailed=true'
{
  "aiod": 7
}