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

APIError HTTP 500 when updating one tag with existing search_criteria #314

Open
NexCu opened this issue Feb 4, 2018 · 3 comments
Open
Labels

Comments

@NexCu
Copy link

NexCu commented Feb 4, 2018

When I request a tag from Nexpose API, I got all information about it. This includes name, associated_asset_ids, search_criteria etc.

Expected Behavior

When I only update some tag.associated_asset_ids and the tag has also search_criteria, the tag should be updated without any issue.

Current Behavior

After updating of existing tag object for values in tag.associated_asset_ids, I do a tag.save(connection) and get an Error HTTP 500. Tags without search criteria can be updated without problems and I get HTTP 200 answer from Nexpose.

After some research I found the reason, but I don't understand why it is raised without change anything für search_criteria.

2018-02-04T12:29:16 [WARN] [Thread: http-nio-443-exec-172=/api/2.0/tags/9767] Encountered an internal server error.
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT INTO tag_criteria_asset_bridge (tag_id, asset_id) VALUES (?, ?)]; ERROR: duplicate key value violates unique constraint "tag_criteria_asset_bridge_pkey"
Detail: Key (tag_id, asset_id)=(9767, 3705) already exists.; nested exception is org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "tag_criteria_asset_bridge_pkey"
Detail: Key (tag_id, asset_id)=(9767, 3705) already exists.

Your Environment

  • Nexpose gem version: 7.2.0
  • Ruby version: 2.5.0p0 (2017-12-25 revision 61468)
  • Operating System and version: CentOS
  • Nexpose product version: 6.5.4

Thanks for any support.

@tschmidtke-r7
Copy link

tschmidtke-r7 commented Feb 5, 2018

This functionality was broken in 7.1.1 last I checked and I believe that is still the case in 7.2.0 based on commit activity. As a workaround, I recommend doing the following:

  1. Save the current tag criteria to a variable
  2. Clear the tag's criteria using the below code sample where nsc is your Nexpose::Connection object and tag.id is the ID of the tag.
Nexpose::AJAX.post(nsc, "/data/tag/criteria?entityid=#{tag.id}", payload ='{"searchCriteria": null}', content_type = Nexpose::AJAX::CONTENT_TYPE::JSON)
  1. Set the tag criteria
    tag.search_criteria = tag_criteria
  2. Save the tag
    tag.save(nsc)

Hope that helps!

@NexCu
Copy link
Author

NexCu commented Feb 6, 2018

This simply works perfect. Great Thanks!

@gschneider-r7
Copy link
Contributor

This could be from a change on the underlying API in Nexpose as I didn't see any changes in the gem that would have caused this, at least from a quick glance.

Also instead of modifying the associated_asset_ids property directly I recommend using the tag.add_to_asset method for manually tagging assets.

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

No branches or pull requests

3 participants