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

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

Open
redbar0n opened this issue Apr 26, 2017 · 2 comments
Open

Comments

@redbar0n
Copy link

redbar0n commented Apr 26, 2017

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.

@redbar0n
Copy link
Author

I just ran into this again. Really confusing and misleading.

Looks like the culprit is here:
https://github.com/cldwalker/hirb/blob/master/lib/hirb/helpers/table.rb#L273

@redbar0n
Copy link
Author

I am particularly wondering the rationale behind this part:

(cell_width < 5) ? String.slice(value, 0, cell_width)

Is there a reason (unbeknownst to me) to ignore the truncation with '...' if the cell width is smaller than 5?

The surrounding context is if the value is greater than the cell width. It seems appropriate to always truncate the value with '...' then.

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

No branches or pull requests

1 participant