Skip to content
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

_Exception: Exception: Could not save product - API V2 - status=0 - errors=null #5864

Closed
sentry-io bot opened this issue Nov 16, 2024 · 10 comments · Fixed by openfoodfacts/openfoodfacts-server#11032

Comments

@sentry-io
Copy link

sentry-io bot commented Nov 16, 2024

Sentry Issue: SMOOTHIE-3BM

_Exception: Exception: Could not save product - API V2 - status=0 - errors=null
  File "stacktrace_utils.dart", line 10, in getCurrentStackTrace
  File "sentry_exception_factory.dart", line 44, in SentryExceptionFactory.getSentryException
  File "sentry_client.dart", line 235, in SentryClient._prepareEvent
  File "sentry_client.dart", line 119, in SentryClient.captureEvent
  File "hub.dart", line 173, in Hub.captureException
@monsieurtanuki
Copy link
Contributor

@stephanegigandet Could it be that now you return 0 instead of 1 for a successful save product /cgi/product_jqm2.pl action?

@BathoryPeter
Copy link
Contributor

I see the same error in Pending contributions, and my edits are not uploaded to the server.
Version 4.16.1 on Android 14

@teolemon
Copy link
Member

@stephanegigandet I'm seeing those too, after checking.

@stephanegigandet
Copy link
Contributor

Is there a way to see the actual query that is sent to the server? Could we log it in Sentry? or maybe it's there already, I didn't find it.

@stephanegigandet
Copy link
Contributor

@monsieurtanuki : @g123k and I had a look, it seems it's probably because the app is sending product_type=null to the write API, with null as a string, so the API fails because it's not a valid type.

Note that API v2 sends back more details in "status_verbose", could you log it in Sentry? That would help debug future errors.

{
   "status" : 0,
   "status_verbose" : "invalid_product_type"
}

I will make a fix server side so that "null" is ignored, and we will default to the server product type (food).

@monsieurtanuki
Copy link
Contributor

@stephanegigandet The thing is that I expect the error to be in the 'error' field of the json body, not in 'status_verbose'.
I guess that in Smoothie we would be better off with "error + status_verbose", right? I mean something like result.error ?? result.status_verbose in dart.

I've just tried to change the product_type to an unknown value in TEST env, and got this message:
{"status_verbose":"No permission: product_change_product_type","status":0}

Fun fact: I've also tried to save a product with explicitly the same product_type, and I still got the same error message.
Looks like the product_type should be set just once.

In the off-dart code, a solution would be to ignore product_type if null / not changed, so that it won't be sent to the server. Working on it.

stephanegigandet added a commit to openfoodfacts/openfoodfacts-server that referenced this issue Nov 21, 2024
I'm hoping this PR will fix
openfoodfacts/smooth-app#5864

If we receive product_type=null, we just ignore it.

Also refactored the code to remove some duplication.
@github-project-automation github-project-automation bot moved this from 💬 To discuss and validate to 🎊 Done in 🤳🥫 The Open Food Facts mobile app (Android & iOS) Nov 21, 2024
@monsieurtanuki
Copy link
Contributor

@stephanegigandet I'm not sure your fix was appropriate enough - anyway, I still had the same "Exception: Could not save product - API V2 - status=0 - errors=invalid_product_type" problem on the beauty.org server after you considered the current issue as fixed.
That's why I coded the following PR, that actually fixed the issue on beauty.org (or maybe your fix did work too, but minutes later).
openfoodfacts/openfoodfacts-dart#996
Your analysis of the reasons of the bug were indeed correct, so kudos to you and @g123k!

@monsieurtanuki
Copy link
Contributor

@stephanegigandet I believe your fix can only work on the food server.

@stephanegigandet
Copy link
Contributor

@stephanegigandet The thing is that I expect the error to be in the 'error' field of the json body, not in 'status_verbose'.
I guess that in Smoothie we would be better off with "error + status_verbose", right? I mean something like result.error ?? result.status_verbose in dart.

If you use API v2, you get an error in status and status verbose:
https://github.com/openfoodfacts/openfoodfacts-server/blob/main/tests/integration/expected_test_results/change_product_code_and_product_type/change-product-type-to-invalid-api-v2-moderator.json

If you use API v3, you get an error in the JSON body:
https://github.com/openfoodfacts/openfoodfacts-server/blob/main/tests/integration/expected_test_results/change_product_code_and_product_type/change-product-type-to-opff-api-v3-invalid-product-type.json

I've just tried to change the product_type to an unknown value in TEST env, and got this message:
{"status_verbose":"No permission: product_change_product_type","status":0}

Changing the product type is currently limited to moderators, that's why you get this message. If the user is not a moderator, we should not offer to change the product type.

@stephanegigandet
Copy link
Contributor

@stephanegigandet I believe your fix can only work on the food server.

It wasn't deployed on the others yet, I deployed it on all flavors on Friday I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

4 participants