Needs work
Project:
Drupal core
Version:
main
Component:
mysql db driver
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
4 Aug 2015 at 13:10 UTC
Updated:
25 Nov 2022 at 17:33 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
stefan.r commentedSo just to make sure I understand correctly, if we have a contrib module that indirectly calls getNormalizedIndexes() without proper testing on dev (or automated tests), actual end users that run into the bug either have assertions on and get the same message (along with a PDOException depending on assert options), or they have assertions off and merely get a database error? Whereas with the SchemaException it will just fail on the exception.
Comment #2
stefan.r commentedComment #4
stefan.r commentedComment #6
Crell commentedThe if statement becomes unnecessary here.
The conceit with assertions is that the error does not get as far as production, so production doesn't need additional error checking in production for that situation.
(If we're not comfortable with that caveat, then we shouldn't switch it to an assertion.)
Comment #7
stefan.r commentedAh that's nifty!
We may be able to live with this, if by chance a contrib module forgets to write tests or manually test any code that adds an index and a user runs into the bug with assertions off this will fail further down the line anyway (without any more damage than what would be happening otherwise).
Comment #8
Crell commentedWe ought to convert this to test for the assertion rather than removing it entirely. Unfortunately, that may be blocked on #2536560: Runtime Assertion unit and functional testing. Otherwise I'm good here.
Comment #9
dawehnerYeah we should keep the test, this is for sure
Comment #10
neclimdulI'm not sure it is OK to silently "pass" returning the unmodified index here if assertions are turned off. The system might pass, but if it fails it is going to throw an exception from inside PDO that is going to be a lot less clear.
Failed: Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes: ALTER TABLE .. ADD INDEX ...; Array ( ) in db_add_index() (line 659 of /.../core/includes/database.inc).Comment #11
stefan.r commentedWell @Crell argued in #6 that if we're worried about that, it shouldn't be an assert() in the first place.
I think it's a minor concern, can't we assume developers always have assertions on? It'd just be end users reporting on that obscure PDOException in contrib issue queues for modules that haven't done manual testing nor automated testing of the code calling addIndex() (mostly update hooks), and it would get fixed/found soon enough.
Comment #12
damien tournoud commentedThis would be valid as an assertion only if the data has already been validated elsewhere. From @neclimdul#10 it is clear that it is not true.
So either we keep the exception as it is, or we need to add actual validation in the caller.
Comment #13
damien tournoud commentedThe rule of a thumb is that assertions are for invariants that should be true if there is no programming error in the same unit. Programming errors in other units (passing invalid arguments, calling a method whose pre-requisites are not met, etc.) are just standard error handling as part of the unit contract, and should use normal exceptions.
Comment #14
Crell commentedI've never heard the "in the same unit" caveat when describing assertion use cases. I generally only here "if it can only possibly happen because of programmer error, assertion. If it's user/environment dependent, exception". Which programmer generally doesn't come up. :-)
Comment #15
damien tournoud commented@Crell: Assertions document logically true conditionals, or said differently, they document conditions that should be absolutely impossible short of a programming error. In most cases, you can only define "logically impossible" conditions inside a single unit, as an unit doesn't control how its exported methods are used.
Comment #16
Crell commentedOr to enforce invariants that go beyond what the type system allows. Eg, the legal values of this parameter are the strings "header" and "footer"; if it's not one of those, it may as well be a type error. Hence assertion.
Comment #17
damien tournoud commented> Or to enforce invariants that go beyond what the type system allows. Eg, the legal values of this parameter are the strings "header" and "footer"; if it's not one of those, it may as well be a type error. Hence assertion.
@Crell: Described like this, in the vast majority of cases those should use normal exceptions (UnexpectedValueException, BadMethodCallException, etc.). Note that TypeError is *not* an assertion. It is not a subclass of AssertionError, nor should it.
Comment #18
stefan.r commentedComment #30
smustgrave commentedSeems like there is still some discussion going on. Can the IS be updated with the final decision? Also this will need a reroll for 10.1