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

Fix 3256 update document when attribute name is numeric #5723

Conversation

faisalill
Copy link
Contributor

What does this PR do?

Replaced array_merge with + operator. array_merge appends the numeric keys from both the arrays and renumbers them starting from 0 , hence giving weird errors like Unknown Attribute: "0". Whereas + operator uses the value from first array in the expression while retaining the same keys.

Test Plan

issue3256.online-video-cutter.com.mp4

Related PRs and Issues

#3256

Checklist

@faisalill
Copy link
Contributor Author

@abnegate

Copy link
Contributor

@abnegate abnegate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! Let's add a test in DatabasesBase that check this fix

@faisalill
Copy link
Contributor Author

faisalill commented Jun 19, 2023

@abnegate

What's Changed?

  1. Created a new collection named test_numeric_key.
  2. Created an attribute 1 in test_numerick_key collection.
  3. Created a document and updated it.
  4. Wrote tests for each new thing added.

Test Plan

docker compose exec appwrite test /usr/src/code/tests/e2e/Services/Databases returned no errors.

Copy link
Contributor

@abnegate abnegate left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a new test for the changes, called testNumericOnlyAttributes, to keep the concerns separate from the other tests

@faisalill
Copy link
Contributor Author

@abnegate
Added the changes as you said.

tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
tests/e2e/Services/Databases/DatabasesBase.php Outdated Show resolved Hide resolved
@faisalill
Copy link
Contributor Author

@abnegate
Did the changes you said.

@faisalill
Copy link
Contributor Author

@abnegate
Did the changes.

@faisalill
Copy link
Contributor Author

faisalill commented Jul 10, 2023

@fogelito can you review this PR please.

@@ -3279,7 +3279,7 @@ function updateAttribute(
$permissions = $document->getPermissions() ?? [];
}

$data = \array_merge($document->getArrayCopy(), $data); // Merge existing data with new data
$data = $data + $document->getArrayCopy(); // Merge existing data with new data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @fanatic75 solve this issue with array_merge_recursive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, array_merge_recursive might be worth exploring


$this->assertEquals($document['body']['1'], 'one updated');
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add two more tests, please?
one for find and second for getDocument , while trying to use the select query operator for this specific attribute?
for checking validations are passed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fogelito this can be solved using + operator as well although I think we should first discuss if we want to allow attribute with numeric names or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 👍

@fanatic75
Copy link
Contributor

@faisalill I think we have a change of plans; We will not allow attributes with numeric names.
cc @stnguyen90

@faisalill
Copy link
Contributor Author

@fanatic75 imma close this PR then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants