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

Snipe IT Hardware API PATCH/PUT doesn't update text fields with null or blank value. #6113

Closed
2 tasks done
nhut opened this issue Aug 22, 2018 · 8 comments
Closed
2 tasks done
Labels
api ✋ bug Confirmed bug
Milestone

Comments

@nhut
Copy link

nhut commented Aug 22, 2018

Please confirm you have done the following before posting your bug report:

Describe the bug
Snipe IT Hardware API PATCH/PUT doesn't update text fields with null or blank value for example "name", "serial", "notes", custom field strings...

To Reproduce
Step 1. Let's start with updating hardware name value to "hardware name".
URL: https://develop.snipeitapp.com/api/v1/hardware/16
Http method: PATCH
Request body content:

{
  "name": "hardware name"
}

And we get API response with body content:

{
    "status": "success",
    "messages": "Asset updated successfully.",
    "payload": {
        "id": 16,
        "name": "hardware name",
        "asset_tag": "877162936",
        "model_id": 1,
        "serial": "7d43eec5-efd5-3879-b669-59e419f9279f",
        "purchase_date": "2018-03-08 00:00:00",
        "purchase_cost": "2099.16",
        "order_number": "10861138",
        "assigned_to": null,
        "notes": "Created by DB seeder",
        "image": null,
        "user_id": 1,
        "created_at": "2018-07-24 21:00:09",
        "updated_at": "2018-08-22 05:11:26",
        "physical": 1,
        "deleted_at": null,
        "status_id": 1,
        "archived": 0,
        "warranty_months": null,
        "depreciate": null,
        "supplier_id": 1,
        "requestable": 1,
        "rtd_location_id": 5,
        "accepted": null,
        "last_checkout": null,
        "expected_checkin": null,
        "company_id": null,
        "assigned_type": null,
        "last_audit_date": null,
        "next_audit_date": null,
        "location_id": 5,
        "checkin_counter": 0,
        "checkout_counter": 0,
        "requests_counter": 1,
        "_snipeit_focused_real_time_attitude_1": null,
        "_snipeit_innovative_3rdgeneration_time_frame_2": null,
        "_snipeit_function_based_cohesive_groupware_3": null,
        "_snipeit_devolved_bi_directional_model_4": null,
        "_snipeit_nuovo_widget_5": null,
        "_snipeit_ministry_6": null,
        "_snipeit_datasourceofasset_7": null,
        "_snipeit_test_8": null
    }
}

Step 2. Update hardware name value to "".
URL: https://develop.snipeitapp.com/api/v1/hardware/16
Http method: PATCH
Request body content:

{
  "name": ""
}

And we get API response:

{
    "status": "success",
    "messages": "Asset updated successfully.",
    "payload": {
        "id": 16,
        **"name": "hardware name",**
        "asset_tag": "877162936",
        "model_id": 1,
        "serial": "7d43eec5-efd5-3879-b669-59e419f9279f",
        "purchase_date": "2018-03-08 00:00:00",
        "purchase_cost": "2099.16",
        "order_number": "10861138",
        "assigned_to": null,
        "notes": "Created by DB seeder",
        "image": null,
        "user_id": 1,
        "created_at": "2018-07-24 21:00:09",
        "updated_at": "2018-08-22 05:11:26",
        "physical": 1,
        "deleted_at": null,
        "status_id": 1,
        "archived": 0,
        "warranty_months": null,
        "depreciate": null,
        "supplier_id": 1,
        "requestable": 1,
        "rtd_location_id": 5,
        "accepted": null,
        "last_checkout": null,
        "expected_checkin": null,
        "company_id": null,
        "assigned_type": null,
        "last_audit_date": null,
        "next_audit_date": null,
        "location_id": 5,
        "checkin_counter": 0,
        "checkout_counter": 0,
        "requests_counter": 1,
        "_snipeit_focused_real_time_attitude_1": null,
        "_snipeit_innovative_3rdgeneration_time_frame_2": null,
        "_snipeit_function_based_cohesive_groupware_3": null,
        "_snipeit_devolved_bi_directional_model_4": null,
        "_snipeit_nuovo_widget_5": null,
        "_snipeit_ministry_6": null,
        "_snipeit_datasourceofasset_7": null,
        "_snipeit_test_8": null
    }
}

Expected behavior
name-field value should be updated to "" and API should respond with:

{
    "status": "success",
    "messages": "Asset updated successfully.",
    "payload": {
        "id": 16,
        "name": "",
        "asset_tag": "877162936",
        "model_id": 1,
        "serial": "7d43eec5-efd5-3879-b669-59e419f9279f",
        "purchase_date": "2018-03-08 00:00:00",
        "purchase_cost": "2099.16",
        "order_number": "10861138",
        "assigned_to": null,
        "notes": "Created by DB seeder",
        "image": null,
        "user_id": 1,
        "created_at": "2018-07-24 21:00:09",
        "updated_at": "2018-08-22 05:11:26",
        "physical": 1,
        "deleted_at": null,
        "status_id": 1,
        "archived": 0,
        "warranty_months": null,
        "depreciate": null,
        "supplier_id": 1,
        "requestable": 1,
        "rtd_location_id": 5,
        "accepted": null,
        "last_checkout": null,
        "expected_checkin": null,
        "company_id": null,
        "assigned_type": null,
        "last_audit_date": null,
        "next_audit_date": null,
        "location_id": 5,
        "checkin_counter": 0,
        "checkout_counter": 0,
        "requests_counter": 1,
        "_snipeit_focused_real_time_attitude_1": null,
        "_snipeit_innovative_3rdgeneration_time_frame_2": null,
        "_snipeit_function_based_cohesive_groupware_3": null,
        "_snipeit_devolved_bi_directional_model_4": null,
        "_snipeit_nuovo_widget_5": null,
        "_snipeit_ministry_6": null,
        "_snipeit_datasourceofasset_7": null,
        "_snipeit_test_8": null
    }
}

Server (please complete the following information):

Desktop (please complete the following information):

  • Postman
@stale
Copy link

stale bot commented Oct 21, 2018

Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!

@stale stale bot added the stale label Oct 21, 2018
@nhut
Copy link
Author

nhut commented Oct 21, 2018

Yes, it's still relevant.

@stale
Copy link

stale bot commented Oct 21, 2018

Okay, it looks like this issue or feature request might still be important. We'll re-open it for now. Thank you for letting us know!

@stale stale bot removed the stale label Oct 21, 2018
@ryan3anderson
Copy link

I'm running in to the same issue with this. Have there been any updates on this? I need to blank out a field via the API but it seems to ignore blank or null updates.

@Sxderp
Copy link
Contributor

Sxderp commented Jan 15, 2019

The problem with the API is that it's using a completely separate code path. Which leads to duplicated code to do the same things. The backend processing should really be merged. I don't really understand why they're different. If you watch the network requests that your browser makes when updating objects you can see that they request content is almost identical to what's required for the APIs.

For example take a look at the User controller for web requests and the one for api requests. Aside from the method of confirming authorization to perform the update (which should be abstracted elsewhere in the program) and the returned response the actions these functions perform should ostensibly be the same. Hopefully this problem can get rectified in the future.

@snipe
Copy link
Owner

snipe commented Feb 6, 2019

The problem with the API is that it's using a completely separate code path. Which leads to duplicated code to do the same things. The backend processing should really be merged. I don't really understand why they're different.

Because building a REST API takes time, and you don't get a lot of opportunity to change your mind once people start using it. We had the option of releasing it in steps, or making people wait to get anything at all, and we opted to release it in steps. It's not that complicated to understand.

Hopefully this problem can get rectified in the future.

Pull requests are always welcome.

snipe added a commit that referenced this issue Feb 7, 2019
…ia API

Need to confirm that re-enabling `\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,` won’t mangle anything. I know we ran into some issues when testing a long time ago, but not sure thos issues apply anymore, and I can’t remember what they were.
@snipe
Copy link
Owner

snipe commented Feb 7, 2019

@nhut @ryan3anderson I've just pushed out a possible fix for this issue. Can you pull that feature branch and see if that resolves it for you?

#6693

@snipe snipe added this to the v5.0 milestone Feb 7, 2019
@snipe snipe added ✋ bug Confirmed bug api labels Feb 7, 2019
@snipe snipe closed this as completed in 90cddb7 Feb 13, 2019
@nhut
Copy link
Author

nhut commented Feb 15, 2019

@nhut @ryan3anderson I've just pushed out a possible fix for this issue. Can you pull that feature branch and see if that resolves it for you?

#6693

I tried a moment ago and it gives http 500 internal server error (html page).

Is the change at https://develop.snipeitapp.com ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api ✋ bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

4 participants