Skip to content

Hirb truncates ID without any indication, in tables with many columns #101

Open
@redbar0n

Description

irb(main):043:0> User.find_by_email('[email protected]')
D, [2017-04-26T15:55:44.739925 #7482] DEBUG -- :   User Load (218.9ms)  EXEC sp_executesql N'SELECT [users].* FROM [users] WHERE (emails LIKE N''%[email protected]%'') ORDER BY created_at ASC'
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| id   | emai | crea | up... | na... | firs | st... | city | birt | tl... | zi... | last | crm_ | can_ | ty... | me... | me... | loca | has_ | last | mc_m | mo... | last | guid |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| 7018 | lise | 2017 | 20... | true  | Roy  | Sk... | MATH | 1951 | 91... | 5174  | Mykl | 9179 | fals | Me... | 20... | 20... | 8200 | true | 2017 | true | false | 2017 | CA55 |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
1 row in set
irb(main):044:0> User.find 7018
D, [2017-04-26T15:55:53.044146 #7482] DEBUG -- :   User Load (1.1ms)  EXEC sp_executesql N'SELECT TOP (1) [users].* FROM [users] WHERE [users].[id] = @0', N'@0 int', @0 = 7018  [["id", 7018]]
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| id   | emai | crea | up... | na... | firs | st... | city | birt | tl... | zi... | last | crm_ | can_ | ty... | me... | me... | loca | has_ | last | mc_m | mo... | last | guid |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| 7018 | tore | 2015 | 20... | true  | Tore | Fi... | OSLO | 1957 | 92... | 1182  | Jørg | 6552 | fals | Me... | 19... | 20... | 8200 | true | 2017 | fals | false | 2016 |      |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
1 row in set
irb(main):045:0> User.where(id: 7018)
D, [2017-04-26T15:56:18.476991 #7482] DEBUG -- :   User Load (2.6ms)  EXEC sp_executesql N'SELECT [users].* FROM [users] WHERE [users].[id] = 7018'
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| id   | emai | crea | up... | na... | firs | st... | city | birt | tl... | zi... | last | crm_ | can_ | ty... | me... | me... | loca | has_ | last | mc_m | mo... | last | guid |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
| 7018 | tore | 2015 | 20... | true  | Tore | Fi... | OSLO | 1957 | 92... | 1182  | Jørg | 6552 | fals | Me... | 19... | 20... | 8200 | true | 2017 | fals | false | 2016 |      |
+------+------+------+-------+-------+------+-------+------+------+-------+-------+------+------+------+-------+-------+-------+------+------+------+------+-------+------+------+
1 row in set
irb(main):046:0> User.find_by_email('[email protected]').id
D, [2017-04-26T15:56:26.473704 #7482] DEBUG -- :   User Load (214.5ms)  EXEC sp_executesql N'SELECT [users].* FROM [users] WHERE (emails LIKE N''%[email protected]%'') ORDER BY created_at ASC'
=> 70187

In this case, the appropriate user's id was shown as 7018, but it was actually 70187.
Another user actually had the id 7018.

So, when looking at the table and/or copy-pasting the ID for further use, you might tread very wrong. It's especially dangerous if you delete the user with that ID, only to discover you had actually deleted the wrong user.

Suggested solution:

Display 70... or similar, for the ID, when truncating it, like its done in the other columns. So you realize it's been truncated.

PS: If you inspect the output columns, you see that more columns have the same problem. emai, crea etc.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions