baopham/laravel-dynamodb

Trying to access array offset on value of type null - PHP 7.4.7

AntonyPritchett opened this issue · 3 comments

Describe the bug

Performing a get on model when only searching for the Partition Key results in error "Trying to access array offset on value of type null". I have a composite key defined

I see your commit a656c26 fixed this issue for another scenario.

Schema

Describe your table schema:

protected $primaryKey = ['userId'];
  protected $compositeKey = ['userId', 'sortKey'];
  protected $dynamoDbIndexKeys = [
    'SortKey' => [ //Global Secondary Index
        'hash' => 'sortKey'
    ],
  ];

Debug info

Show the query that you're having trouble with by copy-pasting the result of:

Trying to get this outputs the error, but my code is:

$personRecords = $this->where('userId', $user->userId)->get();

and stack

  "message": "Trying to access array offset on value of type null",
   "statusCode": 500,
   "debug": {
       "line": 210,
       "file": "/home/vagrant/code/myapp/vendor/baopham/dynamodb/src/ConditionAnalyzer/Analyzer.php",
       "class": "ErrorException",
       "trace": [
           "#0 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/ConditionAnalyzer/Analyzer.php(210): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError()",
           "#1 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/ConditionAnalyzer/Analyzer.php(117): BaoPham\\DynamoDb\\ConditionAnalyzer\\Analyzer->hasValidQueryOperator()",
           "#2 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/ConditionAnalyzer/Analyzer.php(70): BaoPham\\DynamoDb\\ConditionAnalyzer\\Analyzer->identifierConditions()",
           "#3 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/DynamoDbQueryBuilder.php(693): BaoPham\\DynamoDb\\ConditionAnalyzer\\Analyzer->isExactSearch()",
           "#4 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/DynamoDbQueryBuilder.php(663): BaoPham\\DynamoDb\\DynamoDbQueryBuilder->getAll()",
           "#5 /home/vagrant/code/myapp/vendor/baopham/dynamodb/src/DynamoDbQueryBuilder.php(657): BaoPham\\DynamoDb\\DynamoDbQueryBuilder->all()",
           "#6 /home/vagrant/code/myapp/app/Models/Remote/User.php(49): BaoPham\\DynamoDb\\DynamoDbQueryBuilder->get()",

Version info

  • Laravel: 6.18.22
  • laravel-dynamodb: latest

I'm also experiencing this after updating to PHP 7.4, when I try to query a model with a composite key, using only the partition key

protected $compositeKey = ['dbName','uuid'];

protected $dynamoDbIndexKeys = [
  'dbName-index' => [
    'hash' => 'dbName'
  ]
];

$objects = Model::where(['dbName' => $dbName])->get();

I don't know why this stopped working, but it looks like I can fix it by adding the following code on line 209 of ConditionAnalyzer/Analyzer.php

if (!$rangeCondition) { return false; }

Hey, sorry for the delay in getting this sorted, this is fixed in v6.1.1 (#226)