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

Licensing, Expressions: column 'lastUpdateDate' cannot be null #543

Open
t4k opened this issue Feb 27, 2019 · 1 comment
Open

Licensing, Expressions: column 'lastUpdateDate' cannot be null #543

t4k opened this issue Feb 27, 2019 · 1 comment
Assignees
Labels
bug This is a bug (not an enhancement)

Comments

@t4k
Copy link
Contributor

t4k commented Feb 27, 2019

I'm posting the contents of my email to the coral-users list because I think it's a legitimate issue after investigating further. https://lists.coral-erm.org/pipermail/coral-user/2019-February/000506.html

We are getting an error when trying to save an Expression on a license.

There was a problem with the database: Column 'lastUpdateDate' cannot be null

From what I can tell in the code, this makes sense…

`lastUpdateDate` timestamp NOT NULL default CURRENT_TIMESTAMP,
declares that the column in the db cannot be NULL.

if ($value == '' || !isset($value)) {
$value = "NULL";
sets the value of the attribute to NULL if it is sent with nothing.

case 'submitExpression':
//if expressionID is sent then this is an update
if ((isset($_POST['expressionID'])) && ($_POST['expressionID'] != '')){
$expressionID = $_POST['expressionID'];
$expression = new Expression(new NamedArguments(array('primaryKey' => $expressionID)));
}else{
$expression = new Expression();
//default production use (terms tool indicator) to off if this is an add, otherwise we leave it alone
$expression->productionUseInd = 0;
$expression->expressionID = '';
}
$expression->documentText = $_POST['documentText'];
$expression->documentID = $_POST['documentID'];
$expression->expressionTypeID = $_POST['expressionTypeID'];
$expression->productionUseInd = '0';
$expression->simplifiedText = '';
try {
$expression->save();
if (!$expressionID){
$expressionID=$expression->primaryKey;
}
//first remove all qualifiers, then we'll add them back
$expression->removeQualifiers();
foreach (explode(',', $_POST['qualifiers']) as $id){
if ($id){
$expressionQualifierProfile = new ExpressionQualifierProfile();
$expressionQualifierProfile->expressionID = $expressionID;
$expressionQualifierProfile->qualifierID = $id;
$expressionQualifierProfile->save();
}
}
} catch (Exception $e) {
echo $e->getMessage();
}
break;
does not set lastUpdateDate anywhere.

I'm puzzled why I cannot reproduce the error on any test instances, only on our production instance.

The production instance is using:
PHP Version 7.0.33-0ubuntu0.16.04.1
MySQL Server version: 5.6.40-log Source distribution (AWS RDS)
Apache/2.4.18 (Ubuntu)

@t4k t4k self-assigned this Feb 27, 2019
@t4k t4k added the bug This is a bug (not an enhancement) label Feb 27, 2019
t4k added a commit to caltechlibrary/coral that referenced this issue Feb 27, 2019
The real changes besides white space include:

- set `$expression->productionUseInd` to a string in the `else` clause
- avoid rewriting `$expression->productionUseInd` immediately after the `else` clause (if it is an update and the value is already set, it would have been always overwritten)
- set `$expression->lastUpdateDate = date('Y-m-d H:i:s');` so that we don't get the cannot be null error
@t4k
Copy link
Contributor Author

t4k commented May 3, 2019

I have discovered what the problem is for our setup.

AWS RDS MySQL sets the explicit_defaults_for_timestamp option to TRUE in its default parameter group for MySQL 5.6. It can only be changed by someone going in and adjusting a custom parameter for that setting to FALSE and restarting the database service. (See: https://forums.aws.amazon.com/thread.jspa?threadID=132676)

Although this is an edge case, I believe the CORAL code can be improved to overcome it. It is very possible that someone may come along and attempt to use AWS RDS with MySQL 5.6 with default settings and hit the same problem as I did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug (not an enhancement)
Projects
None yet
Development

No branches or pull requests

1 participant