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

Requesting a regular transfer transaction as an admin fails #7

Open
Nefrin opened this issue Jul 9, 2019 · 0 comments
Open

Requesting a regular transfer transaction as an admin fails #7

Nefrin opened this issue Jul 9, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@Nefrin
Copy link
Contributor

Nefrin commented Jul 9, 2019

Problem:
Sending a POST request to /v1/transactions/transfer with a valid JSON body in the regular transfer form (no sender field) will result in a 500 Internal server error response.

POST /v1/transactions/transfer HTTP/1.1
Host: localhost:8080
Content-Type: application/json
Authorization: Basic QWRtaW46VGVzdFBhc3N3b3JkMQ==
User-Agent: PostmanRuntime/7.15.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 8008289b-c8cf-443f-87cc-2070a2201ac8,6841da77-9abb-4bc1-80c5-5ea2072d1a53
Host: localhost:8080
accept-encoding: gzip, deflate
content-length: 38
Connection: keep-alive
cache-control: no-cache

{
   "receiver": 2,
   "amount": 500
}

Other Symptoms:
The server at this point throws a java.sql.SQLIntegrityConstraintViolationException as a result of a foreign key constraint failing.

 java.sql.SQLIntegrityConstraintViolationException:
 Cannot add or update a child row: a foreign key constraint fails 
(`matohmat`.`transactions`, 
    CONSTRAINT `fk_transaction_sender` 
    FOREIGN KEY (`sender`) 
    REFERENCES `users` (`id`))

Possible cause:
Requesting all admins shows, that all admins have a user_id of 0.

[{
        "id": 3,
        "user_id": 0, /* THIS */
        "balance": 156,
        "last_seen": "2019-07-07T15:18:05",
        "available": true,
        "user_name": "Admin",
        "email": "fachsachft-in@th-nuernberg.de"
    },
    {
        "id": 4,
        "user_id": 0, /* AND THIS */
        "balance": 0,
        "last_seen": "2019-07-07T15:23:54",
        "available": false,
        "user_name": "newadminyadp6lhg",
        "email": "newadminyadp6lhg@th-nuernberg.de"
    }]

This in itself is an invalid value as IDs start at 1. Using this 0 value as sender ID will make the foreign key constraint fail for the same reason.
Root cause of this might be me failing to implement admin-user creation correctly, missing the read-back of the created users id into the admin user_id

@Nefrin Nefrin added the bug Something isn't working label Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant