-
Notifications
You must be signed in to change notification settings - Fork 98
Wrong json returned from the api #1590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@Leptopoda, it looks like your fix for returning recipe IDs as strings doesn't work for the recipe stubs because the API endpoints that return recipe stubs do not pass the results through the I think this is where the Recipe API returns the full recipe json, which it seems to read from the recipe.json file and then pass through the output filter (on line 94), where the cookbook/lib/Controller/Implementation/RecipeImplementation.php Lines 82 to 97 in 3e3a9aa
However, the recipe stub APIs query the database directly and return the results without going through the output filter. Here is one example, from the API for getting all of the recipes for a given category: cookbook/lib/Controller/Implementation/RecipeImplementation.php Lines 282 to 310 in 3e3a9aa
The corresponding DB query is here: Line 252 in 3e3a9aa
My guess is the recipe ID from that query (and others) is being returned as an int (at least, the recipe ID is an int in my DB), and the API on your instance is never changing it to a string (although, on my instance of NC 25.0.6 with Cookbook 0.10.2, it is getting converted to a string, but I'm not sure why). I don't have a way to test this, and I'm not seeing the recipe IDs being returned as ints on my instance, so I'm not sure if I can help fix this directly, but hopefully that can help you fix it? Maybe adding something like this to the foreach loop in
If that works, it would probably need to be added to all the places where a recipe stub is returned, so maybe there is a better way to do it in one place. |
Oh thanks for the hint. I wonder if a DB migration would be better? nevertheless thanks a lot for finding my mistakes :) |
Digging into this a bit more, it looks like the underlying issue stems from a change between php-8.0 and php-8.1 that altered how the PDO-mysql driver returns numeric values from the database. Up to and including php-8.0, by default, integers were returned as strings from the database, so the I think the question now is whether this should be fixed at the database layer (ie, normalize the data coming out of The unit tests covering the database layer rely on On the other hand, the unit tests covering the @christianlupus, it would be great to get your thoughts on where the fix for this issue belongs: the DB layer or the controller layer. |
Description
like #1464 but this time with the recipe_stub it can be seen in the categories and recipe api endpoint.
adding a simple
$json['recipe_id'] = strval($json['recipe_id']);
tohttps://github.com./Leptopoda/cookbook/blob/1fd2668f0ca1311b0585fda5effeeabea1f42d6a/lib/Helper/Filter/JSON/RecipeIdTypeFilter.php#L15
Did not fix it and my php was not good enough to find out why :)
Reproduction
see #1464
Expected behavior
recipe_id
is a StringActual behavior
recipe_id
is an integerScreenshots
Browser
n.a.
Versions
Nextcloud server version: 26.0.0
Cookbook version: 0.10.2
Database system: Sqlite and MariaDB
The text was updated successfully, but these errors were encountered: