Skip to content

Commit

Permalink
removed payload value check from db action upload validation (#1578)
Browse files Browse the repository at this point in the history
* removed payload value check from db action upload

* removed extra space

* huggingface-hub==0.25.2

---------

Co-authored-by: spandan.mondal <[email protected]>
  • Loading branch information
hasinaxp and spandan.mondal authored Oct 22, 2024
1 parent 8203cc5 commit 70fa183
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion kairon/shared/callback/data_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def get_callback_url(bot: str, name: str):
return callback_url



class CallbackRecordStatusType(Enum):
SUCCESS = "SUCCESS"
FAILED = "FAILED"
Expand Down
4 changes: 2 additions & 2 deletions kairon/shared/data/data_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def validate_form_validation_action(bot: str, data: dict):
def validate_database_action(bot: str, data: dict):
data_error = []
for idx, item in enumerate(data.get('payload', [])):
if not item.get('query_type') or not item.get('type') or not item.get('value'):
data_error.append(f"Payload {idx} must contain fields 'query_type', 'type' and 'value'!")
if not item.get('query_type') or not item.get('type'):
data_error.append(f"Payload {idx} must contain fields 'query_type' and 'type'!")
if item.get('query_type') not in [qtype.value for qtype in DbActionOperationType]:
data_error.append(f"Unknown query_type found: {item['query_type']} in payload {idx}")
return data_error
Expand Down
3 changes: 2 additions & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ litellm==1.39.5
jsonschema_rs==0.18.1
mongoengine-jsonschema==0.1.3
fernet==1.0.1
google-generativeai
google-generativeai
huggingface-hub==0.25.2
11 changes: 4 additions & 7 deletions tests/unit_test/data_processor/action_serializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,16 @@ def test_data_validator_validate_database_action():

# Test case 2: Invalid payload (missing query_type)
data["payload"][0]["query_type"] = None
assert DataValidation.validate_database_action(bot, data) == ["Payload 0 must contain fields 'query_type', 'type' and 'value'!", 'Unknown query_type found: None in payload 0']
assert DataValidation.validate_database_action(bot, data) == ["Payload 0 must contain fields 'query_type' and 'type'!", 'Unknown query_type found: None in payload 0']

# Test case 3: Invalid payload (missing type)
data["payload"][0]["query_type"] = list(db_action_operation_types)[0]
data["payload"][0]["type"] = None
assert DataValidation.validate_database_action(bot, data) == ["Payload 0 must contain fields 'query_type', 'type' and 'value'!"]
assert DataValidation.validate_database_action(bot, data) == ["Payload 0 must contain fields 'query_type' and 'type'!"]

# Test case 4: Invalid payload (missing value)
data["payload"][0]["type"] = "type1"
data["payload"][0]["value"] = None
assert DataValidation.validate_database_action(bot, data) == ["Payload 0 must contain fields 'query_type', 'type' and 'value'!"]

# Test case 5: Invalid payload (invalid query_type)
# Test case 4: Invalid payload (invalid query_type)
data["payload"][0]["type"] = 'type1'
data["payload"][0]["value"] = "value1"
data["payload"][0]["query_type"] = "invalid_query_type"
assert DataValidation.validate_database_action(bot, data) == ["Unknown query_type found: invalid_query_type in payload 0", ]
Expand Down

0 comments on commit 70fa183

Please sign in to comment.