mts-ai / FastAPI-JSONAPI

JSON:API for FastAPI
https://mts-ai.github.io/FastAPI-JSONAPI/
MIT License
105 stars 9 forks source link

New sqlalchemy filtering errors #75

Open mahenzon opened 8 months ago

mahenzon commented 8 months ago

0: error processing invalid filters (value instead of val)

[
  {
    "name": "meta",
    "op": "eq",
    "val": {"foo":  "bar"}
  }
]

You'll get an error here:

https://github.com/mts-ai/FastAPI-JSONAPI/blob/3e68db50e8288ca9019846e830b7b647478d511b/fastapi_jsonapi/data_layers/filtering/sqlalchemy.py#L254

1: error processing json

Try creating a filter like this:

[
  {
    "name": "meta",
    "op": "eq",
    "val": {"foo":  "bar"}
  }
]

The problem is here: https://github.com/mts-ai/FastAPI-JSONAPI/blob/3e68db50e8288ca9019846e830b7b647478d511b/fastapi_jsonapi/data_layers/filtering/sqlalchemy.py#L199-L201

mahenzon commented 8 months ago

можно взять как отправную точку вот такую переделку. Но надо ещё списки обрабатывать

fields = {
    schema_field.name: (schema_field.outer_type_, schema_field.field_info),
}

class Config:
    arbitrary_types_allowed = True

# Create the model using create_model
ValidationModel = pydantic.create_model(
    "ValidationModel",
    **fields,
    __config__=Config,
)
validated = ValidationModel.parse_obj({schema_field.name: value})
val = getattr(validated, schema_field.name)
return getattr(model_column, operator)(val)