8000 Set min length to 0 for default value for string attributes by abnegate · Pull Request #5602 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Set min length to 0 for default value for string attributes #5602

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

Merged
merged 2 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Version 1.4.0

## Bugs

- Fix string attribute not allowing default with 0 length [#5602](https://github.com/appwrite/appwrite/pull/5602)

# Version 1.3.4

## Bugs

- Update migration to properly migrate bucket permissiosn [#5497](https://github.com/appwrite/appwrite/pull/5497)
- Update migration to properly migrate bucket permissions [#5497](https://github.com/appwrite/appwrite/pull/5497)

# Version 1.3.3

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/databases.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ function updateAttribute(
->param('key', '', new Key(), 'Attribute Key.')
->param('size', null, new Range(1, APP_DATABASE_ATTRIBUTE_STRING_MAX_LENGTH, Range::TYPE_INTEGER), 'Attribute size for text attributes, in number of characters.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('default', null, new Text(0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('default', null, new Text(0, 0), 'Default value for attribute when not provided. Cannot be set when attribute is required.', true)
->param('array', false, new Boolean(), 'Is attribute an array?', true)
->inject('response')
->inject('dbForProject')
Expand All @@ -1112,7 +1112,7 @@ function updateAttribute(
->action(function (string $databaseId, string $collectionId, string $key, ?int $size, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $database, Event $events) {

// Ensure attribute default is within required size
$validator = new Text($size);
$validator = new Text($size, 0);
if (!is_null($default) && !$validator->isValid($default)) {
throw new Exception(Exception::ATTRIBUTE_VALUE_INVALID, $validator->getDescription());
}
Expand Down Expand Up @@ -1777,7 +1777,7 @@ function updateAttribute(
->param('collectionId', '', new UID(), 'Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).')
->param('key', '', new Key(), 'Attribute Key.')
->param('required', null, new Boolean(), 'Is attribute required?')
->param('default', null, new Nullable(new Text(0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
->param('default', null, new Nullable(new Text(0, 0)), 'Default value for attribute when not provided. Cannot be set when attribute is required.')
->inject('response')
->inject('dbForProject')
->inject('events')
Expand Down
32 changes: 26 additions & 6 deletions tests/e2e/Services/Databases/DatabasesBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public function testDisableCollection(array $data): void
public function testCreateAttributes(array $data): array
{
$databaseId = $data['databaseId'];

$title = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
Expand All @@ -167,6 +168,17 @@ public function testCreateAttributes(array $data): array
'required' => true,
]);

$description = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/string', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'description',
'size' => 256,
'required' => false,
'default' => '',
]);

$releaseYear = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/attributes/integer', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
Expand Down Expand Up @@ -226,6 +238,13 @@ public function testCreateAttributes(array $data): array
$this->assertEquals($title['body']['size'], 256);
$this->assertEquals($title['body']['required'], true);

$this->assertEquals(202, $description['headers']['status-code']);
$this->assertEquals($description['body']['key'], 'description');
$this->assertEquals($description['body']['type'], 'string');
$this->assertEquals($description['body']['size'], 256);
$this->assertEquals($description['body']['required'], false);
$this->assertEquals($description['body']['default'], '');

$this->assertEquals(202, $releaseYear['headers']['status-code']);
$this->assertEquals($releaseYear['body']['key'], 'releaseYear');
$this->assertEquals($releaseYear['body']['type'], 'integer');
Expand Down Expand Up @@ -266,13 +285,14 @@ public function testCreateAttributes(array $data): array
]), []);

$this->assertIsArray($movies['body']['attributes']);
$this->assertCount(6, $movies['body']['attributes']);
$this->assertCount(7, $movies['body']['attributes']);
$this->assertEquals($movies['body']['attributes'][0]['key'], $title['body']['key']);
$this->assertEquals($movies['body']['attributes'][1]['key'], $releaseYear['body']['key']);
$this->assertEquals($movies['body']['attributes'][2]['key'], $duration['body']['key']);
$this->assertEquals($movies['body']['attributes'][3]['key'], $actors['body']['key']);
$this->assertEquals($movies['body']['attributes'][4]['key'], $datetime['body']['key']);
$this->assertEquals($movies['body']['attributes'][5]['key'], $relationship['body']['key']);
$this->assertEquals($movies['body']['attributes'][1]['key'], $description['body']['key']);
$this->assertEquals($movies['body']['attributes'][2]['key'], $releaseYear['body']['key']);
$this->assertEquals($movies['body']['attributes'][3]['key'], $duration['body']['key']);
$this->assertEquals($movies['body']['attributes'][4]['key'], $actors['body']['key']);
$this->assertEquals($movies['body']['attributes'][5]['key'], $datetime['body']['key']);
$this->assertEquals($movies['body']['attributes'][6]['key'], $relationship['body']['key']);

return $data;
}
Expand Down
0