Skip to content

feat(tables_db): add client-side row validation against table schema closes #134 - #162

Closed
GauravPatil2515 wants to merge 1 commit into
appwrite:mainfrom
GauravPatil2515:feat/client-side-row-validation
Closed

GauravPatil2515 wants to merge 1 commit into
appwrite:mainfrom
GauravPatil2515:feat/client-side-row-validation

Conversation

@GauravPatil2515

Copy link
Copy Markdown

Description

Resolves #134

This PR introduces optional client-side schema validation for TablesDB.create_row before network requests are dispatched, catching common data type errors and missing required attributes early with descriptive error messages.

Changes Made

  • Added lightweight validator utility validate_row_data in appwrite/utils/validator.py supporting Appwrite primitive types (string, text, integer, float, boolean, array, etc.)
  • Integrated optional schema parameter into TablesDB.create_row in appwrite/services/tables_db.py
  • Added comprehensive unit tests in test/test_validator.py covering valid payloads, missing required fields, type mismatches, and array validation

How Has This Been Tested?

  • Ran unit tests locally (python3 -m unittest test/test_validator.py) - all 6 tests pass cleanly
  • Verified backward compatibility: when schema=None (default), no validation overhead or behavior changes occur

Signed-off-by: Gaurav Patil <gauravpatil2516@gmail.com>
@github-actions

Copy link
Copy Markdown

This library is auto-generated by the Appwrite SDK Generator, and does not accept pull requests directly. To learn more about how you can help us improve this SDK, please check the contributing guide.

@github-actions github-actions Bot closed this Oct 12, 2026
@hansi-codes

hansi-codes Bot commented Oct 12, 2026

Copy link
Copy Markdown

馃數 Tier A 路 Mergeable after minor fixes

Limited by an open minor finding: Cover validation through create_row

This change adds optional schema-based validation to TablesDB.create_row and introduces a reusable row validator for required fields, primitive types, and arrays. It also adds unit tests for the validator's direct behavior.

Verdict New comments Fixed Still open
馃挰 Commented 1 0 0

Note

@GauravPatil2515 does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve.

Finding Where
馃煛 Cover validation through create_row appwrite/services/tables_db.py:4463
Fix with agent prompt
### Issue 1
appwrite/services/tables_db.py:4463-4464
**Cover validation through create_row**

The new tests call `validate_row_data` directly, while the existing `TablesDB.create_row` test omits `schema`; none verifies that invalid data is rejected before `client.call`. A regression in this integration hook could therefore leave the suite green while the advertised request guard no longer works.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
馃搨 Walkthrough 路 4
File Change
appwrite/services/tables_db.py Adds an optional schema argument and invokes client-side validation before sending a row request.
appwrite/utils/__init__.py Exports the new row-validation helper from the utilities package.
appwrite/utils/validator.py Adds required-field and supported-type checks for row data against column definitions.
test/test_validator.py Adds unit tests for valid payloads, required fields, type mismatches, arrays, and a None schema.
馃攪 Filtered out 路 1

Findings Hansi considered but did not post.

Finding Why
Validate enum column values Verifier: The repository's enum schema is type='string', format='enum', not type='enum' (see test/services/test_tables_db.py:883-892 and 913-921). The existing string mapping and scalar/array isinstance checks therefore already reject integers in actual enum columns. The validator documents required-field and data-type validation, not format/constraint validation; checking allowed elements would extend that scope. The claimed missing enum-type mapping is not a demonstrated bug with the schemas produced by this SDK.

Reviewed 3b26ca9 路 Details 路 Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

馃數 Tier A 路 See the inline comments. Summary

Comment on lines +4463 to +4464
if schema is not None:
validate_row_data(data, schema)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cover validation through create_row

The new tests call validate_row_data directly, while the existing TablesDB.create_row test omits schema; none verifies that invalid data is rejected before client.call. A regression in this integration hook could therefore leave the suite green while the advertised request guard no longer works.

Prompt To Fix With AI
This is a comment left during a code review.
Path: appwrite/services/tables_db.py
Line: 4463-4464

Comment:
**Cover validation through create_row**

The new tests call `validate_row_data` directly, while the existing `TablesDB.create_row` test omits `schema`; none verifies that invalid data is rejected before `client.call`. A regression in this integration hook could therefore leave the suite green while the advertised request guard no longer works.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

馃煛 Minor 路 testing 路 Reply if this doesn't apply.

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.

馃殌 Feature: Python SDK does not validate row data against table schema before insertion

1 participant