I have a SQL function that works when I run it directly from an SQL script and now I'm trying to run it with Manager.raw() in a model method. I wrote a model instance method that worked fine:
def get_store_products_sql(self) -> list['Product']:
return Product.objects.raw(
'''SELECT prod_id AS id,
prod_name,
prod_price
FROM get_store_products(%s)''',
[self.id]
)
Now I'm trying to write a similar class method:
@classmethod
def get_products_by_color_sql(cls, color) -> list['Product']:
return Product.objects.raw(
'''SELECT prod_id AS id,
prod_name,
prod_price
FROM get_products_by_color(%s)''',
[color]
)
This fails pretty silently without even entering get_products_by_color(). color is a legal string and I've also tried simply using "green" without any luck.
As I said, this isn't even getting into the get_products_by_color() function, so I doubt that's the problem. It appears to be either a problem with calling Manager.raw() in a class method or a problem with the color string.