owncloud / testing

🔧 app for testing ownCloud
GNU Affero General Public License v3.0
3 stars 4 forks source link

UniqueConstraintViolationException inside log when adding trusted servers using testing api #131

Closed skshetry closed 4 years ago

skshetry commented 4 years ago

Sample log from https://drone.owncloud.com/owncloud/phoenix/7515/24/13:

{"reqId":"2gbt7aFeIjaM3FErZKjb","level":3,"time":"2020-01-03T06:48:02+00:00","remoteAddr":"172.23.0.10","user":"admin","app":"PHP","method":"POST","url":"\/ocs\/v2.php\/apps\/testing\/api\/v1\/trustedservers?format=json","message":"Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException: An exception occurred while executing 'INSERT INTO `oc_trusted_servers` (`url`, `url_hash`) VALUES(?, ?)' with params [\"http:\\\/\\\/owncloud\", \"668b5fcda851fe516fef14e82973beffe32f385a\"]:\n\nSQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '668b5fcda851fe516fef14e82973beffe32f385a' for key 'url_hash' at \/var\/www\/owncloud\/server\/lib\/composer\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Driver\/AbstractMySQLDriver.php#55"}

Analysis

This happens because we never check if the trusted server is already added. We just catch this error and return happily (which we should). The better way would be to check if the trusted server exists in the DB and then, make a decision (i.e. add or do nothing). This pollutes the log, and could make debugging harder when checking CI failures.