datajoint-python icon indicating copy to clipboard operation
datajoint-python copied to clipboard

add support for decoding foreign key errors

Open ixcat opened this issue 5 years ago • 0 comments
trafficstars

When violating foreign key constraints, the user is presented with low-level SQL details of the constraint which is violated. Example:

IntegrityError(1451, 'Cannot delete or update a parent row: a foreign key constraint fails (`test_fkey_error`.`second`, CONSTRAINT `second_ibfk_1` FOREIGN KEY (`first_id`) REFERENCES `first` (`first_id`) ON DELETE RESTRICT ON UPDATE CASCADE)')

While these error messages are informative enough to debug the problem, they require lower-level knowledge of how MySQL represents foreign key constraints and can be confusing to decipher for users without SQL knowledge. It would be nice to decode these strings into something more DataJoїous (e.g. cannot delete: First.first_id referred to by Second.first_id).

If agreed, I'd think 3 things should result:

  • determine an appropriate DataJoїous representation
  • determine appropriate supporting code (simple decoder function, dj.IntegrityError class + recast constructor, etc)
  • implement

I currently see 3 main places where the issue of 'confusing integrity constraint error' which would be supported, there may be others:

  • too downstream deletes (table has an upstream reference)
  • too-upstream delete_quicks (table has a downstream reference)
  • insertions without needed upstream data

A fully user-friendly implementation would decode/group the attribute references back to their defining classes, however this would be much more complicated from an implementation standpoint; Probably something 'flat' in a more user friendly way would be a good place to start and would still improve usability.

ixcat avatar Jan 24 '20 19:01 ixcat