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

Internal Error when adding CHECK constraint with nonexistent column name #30

Closed
ndmeiri opened this Issue Jul 13, 2015 · 7 comments

Comments

Projects
None yet
2 participants
@ndmeiri

ndmeiri commented Jul 13, 2015

Postico will encounter an "Internal Error" when a user tries to add a CHECK constraint to a column if the column name in the expression does not exist in the table. For example, I have a table with 12 columns:
id, start_date, ..., worker_count, ...
I tired to add a CHECK constraint to the worker_count column by clicking the "+" button, selecting "Check...", and entering the expression workers_count >= 0. Note that the worker_count column is of type smallint.

From the looks of the error (see below), some type of loop isn't stopped before going beyond the bounds of the mutable array that holds the column names. Normally, this is fine because a CHECK constraint expression should only involve existing column names. But, evidently, this throws an exception when the column name is nonexistent.

Also, when I restart Postico after the crash, I can't go back into my table to correct the constant expression. Whenever I try to open the structure of that table, I get a similar "Internal Error" alert. If I choose the "Continue" option in the alert, I just see a blank view. Do you have any temporary workaround ideas for fixing that constraint expression until the issue is fixed?

I encountered the error in v0.24 and was able to reproduce it in v0.25 also.

See below for the error message and stack trace generated by Postico before crashing:

Exception Name: NSRangeException
Description: *** -[__NSArrayM objectAtIndex:]: index 9223372036854775807 beyond bounds [0 .. 11]
User Info: (null)

0   CoreFoundation                      0x00007fff964d3b5c __exceptionPreprocess + 172
1   libobjc.A.dylib                     0x00007fff86fa08e8 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff96392c65 -[__NSArrayM objectAtIndex:] + 245
3   Postico                             0x000000010b78d03c Postico + 307260
4   CoreFoundation                      0x00007fff9648c64c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
5   CoreFoundation                      0x00007fff9648c5bf ___CFXRegistrationPost_block_invoke + 63
6   CoreFoundation                      0x00007fff9648bc87 _CFXRegistrationPost + 407
7   CoreFoundation                      0x00007fff9648b9f2 ___CFXNotificationPost_block_invoke + 50
8   CoreFoundation                      0x00007fff96487e92 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1938
9   CoreFoundation                      0x00007fff96375293 _CFXNotificationPost + 675
10  Foundation                          0x00007fff89ae5bdd -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
11  Postico                             0x000000010b80a38e Postico + 820110
12  CoreFoundation                      0x00007fff9648c64c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
13  CoreFoundation                      0x00007fff9648c5bf ___CFXRegistrationPost_block_invoke + 63
14  CoreFoundation                      0x00007fff9648bc87 _CFXRegistrationPost + 407
15  CoreFoundation                      0x00007fff9648b9f2 ___CFXNotificationPost_block_invoke + 50
16  CoreFoundation                      0x00007fff96487e92 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1938
17  CoreFoundation                      0x00007fff96375293 _CFXNotificationPost + 675
18  Postico                             0x000000010b77d43a Postico + 242746
19  libdispatch.dylib                   0x00007fff8bcb5c5b _dispatch_call_block_and_release + 12
20  libdispatch.dylib                   0x00007fff8bcb1c11 _dispatch_client_callout + 8
21  libdispatch.dylib                   0x00007fff8bcc44ea _dispatch_after_timer_callback + 77
22  libdispatch.dylib                   0x00007fff8bcb1c11 _dispatch_client_callout + 8
23  libdispatch.dylib                   0x00007fff8bcbf53e _dispatch_source_latch_and_call + 2227
24  libdispatch.dylib                   0x00007fff8bcb6f5f _dispatch_source_invoke + 577
25  libdispatch.dylib                   0x00007fff8bcc2aed _dispatch_main_queue_callback_4CF + 414
26  CoreFoundation                      0x00007fff9641ac19 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
27  CoreFoundation                      0x00007fff963d57cd __CFRunLoopRun + 1949
28  CoreFoundation                      0x00007fff963d4dc8 CFRunLoopRunSpecific + 296
29  HIToolbox                           0x00007fff8d679a59 RunCurrentEventLoopInMode + 235
30  HIToolbox                           0x00007fff8d6797ef ReceiveNextEventCommon + 432
31  HIToolbox                           0x00007fff8d67962f _BlockUntilNextEventMatchingListInModeWithFilter + 71
32  AppKit                              0x00007fff8bde679c _DPSNextEvent + 945
33  AppKit                              0x00007fff8c1b45c9 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 343
34  AppKit                              0x00007fff8bddc6dc -[NSApplication run] + 682
35  AppKit                              0x00007fff8bd5eb6d NSApplicationMain + 1176
36  libdyld.dylib                       0x00007fff8ef1b5ad start + 1
@jakob

This comment has been minimized.

Show comment
Hide comment
@jakob

jakob Jul 14, 2015

Owner

Hi! I assume you are running the El Capitan Beta since you get the Internal Error message?

I don't think the problem is related to the typo, that typo should just cause a PostgreSQL error.

Could you send me the full crash report or at least the part with the load address for Postico so I can look up the symbols in the backtrace? The part I'm looking for looks like this:

Binary Images:
       0x10f411000 -        0x10f706ff7 +at.eggerapps.Postico (0.25 - 0.25) <37B69AD9-6528-38B6-8684-01DD855B3583> /Applications/Postico.app/Contents/MacOS/Postico
Owner

jakob commented Jul 14, 2015

Hi! I assume you are running the El Capitan Beta since you get the Internal Error message?

I don't think the problem is related to the typo, that typo should just cause a PostgreSQL error.

Could you send me the full crash report or at least the part with the load address for Postico so I can look up the symbols in the backtrace? The part I'm looking for looks like this:

Binary Images:
       0x10f411000 -        0x10f706ff7 +at.eggerapps.Postico (0.25 - 0.25) <37B69AD9-6528-38B6-8684-01DD855B3583> /Applications/Postico.app/Contents/MacOS/Postico
@jakob

This comment has been minimized.

Show comment
Hide comment
@jakob

jakob Jul 14, 2015

Owner

Hi again! I just looked throught the source and I think I found the cause of the problem. When Postico tries to match constraints with columns, it crashes when it can't find the column a constraint belongs to. (The index 9223372036854775807 is equal to the constant NSNotFound). I've now fixed the crash.

Can you try if this build works?
https://eggerapps-downloads.s3.amazonaws.com/postico-2015-07-14.zip

Unfortunately, your constraint might now disappear, because Postico only shows constraints that are attached to a specific column.

As a workaround, you can look for the constraint in the system table "pg_constraint". Make sure you enabled "Show System Tables" in Postico preferences. You can quickly find recently added constraints by sorting by OID. Then you can delete the constraint using a query like ALTER TABLE tbl_name DROP CONSTRAINT tbl_name_colname_constraint_name (don't just delete the row from the system table!)

Owner

jakob commented Jul 14, 2015

Hi again! I just looked throught the source and I think I found the cause of the problem. When Postico tries to match constraints with columns, it crashes when it can't find the column a constraint belongs to. (The index 9223372036854775807 is equal to the constant NSNotFound). I've now fixed the crash.

Can you try if this build works?
https://eggerapps-downloads.s3.amazonaws.com/postico-2015-07-14.zip

Unfortunately, your constraint might now disappear, because Postico only shows constraints that are attached to a specific column.

As a workaround, you can look for the constraint in the system table "pg_constraint". Make sure you enabled "Show System Tables" in Postico preferences. You can quickly find recently added constraints by sorting by OID. Then you can delete the constraint using a query like ALTER TABLE tbl_name DROP CONSTRAINT tbl_name_colname_constraint_name (don't just delete the row from the system table!)

@ndmeiri

This comment has been minimized.

Show comment
Hide comment
@ndmeiri

ndmeiri Jul 14, 2015

Hello! Thanks for the quick response.
I am running the El Capitan Beta. I should've mentioned that.
The build works, even if I include a typo in the expression.
Thanks for your help! Would you still like me to pass on the full crash report?

ndmeiri commented Jul 14, 2015

Hello! Thanks for the quick response.
I am running the El Capitan Beta. I should've mentioned that.
The build works, even if I include a typo in the expression.
Thanks for your help! Would you still like me to pass on the full crash report?

@ndmeiri

This comment has been minimized.

Show comment
Hide comment
@ndmeiri

ndmeiri Jul 14, 2015

Also, for others who have this same problem: make sure to look in the system table pg_constraint, not pg_constraints.

ndmeiri commented Jul 14, 2015

Also, for others who have this same problem: make sure to look in the system table pg_constraint, not pg_constraints.

@ndmeiri ndmeiri closed this Jul 14, 2015

@jakob

This comment has been minimized.

Show comment
Hide comment
@jakob

jakob Jul 14, 2015

Owner

I fixed the typo, thanks for pointing it out.

I'm curious: what system are you connecting to that allows typos in check constraints? Are you connecting to Redshift? When I mistype a column name on PostgreSQL 9.4, I just get an error stating that the column with that name doesn't exist.

Owner

jakob commented Jul 14, 2015

I fixed the typo, thanks for pointing it out.

I'm curious: what system are you connecting to that allows typos in check constraints? Are you connecting to Redshift? When I mistype a column name on PostgreSQL 9.4, I just get an error stating that the column with that name doesn't exist.

@ndmeiri

This comment has been minimized.

Show comment
Hide comment
@ndmeiri

ndmeiri Jul 14, 2015

Oh, sorry. I misspoke. I meant that Postico correctly reports an error when I mistype a column name in a check constraint (instead of crashing).

ndmeiri commented Jul 14, 2015

Oh, sorry. I misspoke. I meant that Postico correctly reports an error when I mistype a column name in a check constraint (instead of crashing).

@jakob

This comment has been minimized.

Show comment
Hide comment
@jakob

jakob Aug 14, 2015

Owner

Fixed in version 0.26

Owner

jakob commented Aug 14, 2015

Fixed in version 0.26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment