FastAPI-JSONAPI icon indicating copy to clipboard operation
FastAPI-JSONAPI copied to clipboard

mysql version doesn't (yet) support sql syntax

Open srepmub opened this issue 7 months ago • 1 comments

the following works fine:

/handelsproduct/13099/?include=voorschrijfproduct

and also this (one-to-many):

/handelsproduct/13099/relationships/componenten/

but strangely, the following does not (many-to-one):

/handelsproduct/13099/relationships/voorschrijfproduct

even though this is sort of the same as the include above..?

with the following error:

sqlalchemy.exc.NotSupportedError: (pymysql.err.NotSupportedError) (1235, "This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'")
[SQL: SELECT voorschrijfproduct.id, voorschrijfproduct.naam, voorschrijfproduct.emballagetype, voorschrijfproduct.hulpmiddel_aard, voorschrijfproduct.hulpmiddel_hoeveelheid, voorschrijfproduct.meervoudig_product, voorschrijfproduct.reden_hulpstof_id, voorschrijfproduct.extra_kenmerk_voorschrijven, voorschrijfproduct.grootte_algemeen, voorschrijfproduct.opvoer_datum, voorschrijfproduct.mutatie_datum, voorschrijfproduct.verval_datum, voorschrijfproduct.generiekproduct_id 
FROM voorschrijfproduct 
WHERE voorschrijfproduct.id IN (SELECT voorschrijfproduct.id 
FROM handelsproduct INNER JOIN voorschrijfproduct ON voorschrijfproduct.id = handelsproduct.voorschrijfproduct_id 
WHERE handelsproduct.id = %s 
 LIMIT %s, %s)]
[parameters: (13099, 0, 1)]
(Background on this error at: https://sqlalche.me/e/20/tw8g)

I don't think mysql 8.0 is that old..? :S

srepmub avatar Apr 18 '25 08:04 srepmub

my test case works after the following change (so removing the LIMIT part), and all tests still pass:

--- a/fastapi_jsonapi/data_layers/sqla/orm.py
+++ b/fastapi_jsonapi/data_layers/sqla/orm.py
@@ -302,7 +302,7 @@ class SqlalchemyDataLayer(BaseDataLayer):
             fields=[model_id_field],
             select_from=parent_model,
             filters=[parent_id_field == parent_obj_id],
-            size=None if info.many else 1,
+            size=None,
             join=[(self.model, parent_relationship_field)],
         )

I'm not sure why a LIMIT is needed if we follow a many-to-one, since there should never be more than one result anyway..?

srepmub avatar May 20 '25 11:05 srepmub