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
Refactor Http class to utilize ParameterHelper for http_params conver… #130
Refactor Http class to utilize ParameterHelper for http_params conver… #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please find my two cents. And BTW, could you please add some docstring for http tasks? we have some sample in
https://github.com/apache/dolphinscheduler-sdk-python/blob/48586a3702df3f708044c8c03eedd442f21cf24f/src/pydolphinscheduler/tasks/shell.py#L25C1-L44
BTW, since it is an incompatible change, we should add some comments in dolphinscheduler-sdk-python/UPDATING.md Line 29 in 1b2ad57
And we better add some http = Http(
name="http",
url="http://www.google.com",
http_method="GET",
http_params=[
{"prop": "abc", "httpParametersType": "PARAMETER", "value": "def"}
],
) And we should raise some warnings and tell users that the format is deprecation dolphinscheduler-sdk-python/src/pydolphinscheduler/core/task.py Lines 202 to 207 in e1d1527
maybe it can be if isinstance(http_params, list):
warnings.warn(
"The `http_params` parameter currently accept dict instead of list, you parameter is ignore.",
DeprecationWarning,
) |
from pydolphinscheduler.core.parameter import ParameterHelper, ParameterType | ||
from http.py import Http # Replace 'your_module_path' with the actual path or import structure | ||
|
||
def test_http_params_conversion(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! you add some tests for this, but we already have tests for task http in https://github.com/apache/dolphinscheduler-sdk-python/blob/f82e07d232380fe9f5582db4dcca920ae00befd4/tests/tasks/test_http.py could you merge into that file?
Example: | ||
Usage example for creating an HTTP task: | ||
http_task = Http(name="http_task", url="https://api.example.com", http_method="POST", http_params={"key": "value"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you add a good example 👍
src/pydolphinscheduler/tasks/http.py
Outdated
Args: | ||
name (str): The name or identifier for the HTTP task. | ||
url (str): The URL endpoint for the HTTP request. | ||
http_method (str, optional): The HTTP method for the request (GET, POST, etc.). Defaults to HttpMethod.GET. | ||
http_params (str, optional): Parameters for the HTTP request. Defaults to None. | ||
http_check_condition (str, optional): Condition for checking the HTTP response status. | ||
Defaults to HttpCheckCondition.STATUS_CODE_DEFAULT. | ||
condition (str, optional): Additional condition to evaluate if `http_check_condition` is not STATUS_CODE_DEFAULT. | ||
connect_timeout (int, optional): Connection timeout for the HTTP request in milliseconds. Defaults to 60000. | ||
socket_timeout (int, optional): Socket timeout for the HTTP request in milliseconds. Defaults to 60000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change the format to
:param name: A unique, meaningful string for the shell task.
:param command: One or more command want to run in this task.
just like we did in shell task, in this format our docs template can auto fill the parameter type for our users
Hi @HarshitNagpal29, it is good to see you add some tests and fantastic docstring in this PR, well done 👍 +1 |
@zhongjiajie sir i have made all the changes as you mentioned. |
sir please tell me what to do, i am happy to help |
Great, do you have any resources about gsoc 2024? our project join gsoc 2022 but not in 2023, and I have act as mentor for 2022 too. I want to know the timeline about project submission.
you can find my email in my GitHub profile and connect me via that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add some addition comments, PTAL
|
||
# Add any assertions or additional tests as required based on your project's logic | ||
assert isinstance(http_instance.http_params, list) | ||
assert len(http_instance.http_params) == len(http_params_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also add one more test for http_instance.http_params
, cause this is the core concept about what we change in this PR. For example
expect = [
{"prop": "prop1", "direct": "IN", "type": "VARCHAR", "value": "value1"},
{"prop": "prop2", "direct": "IN", "type": "VARCHAR", "value": "value2"},
{"prop": "prop3", "direct": "IN", "type": "VARCHAR", "value": "value3"},
]
assert http.http_params == expect
tests/tasks/test_http.py
Outdated
@@ -126,3 +127,30 @@ def test_http_get_define(): | |||
): | |||
http = Http(name, url) | |||
assert http.task_params == expect_task_params | |||
|
|||
|
|||
def test_http_params_conversion(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
due to you already copy and paste it from file test_http_conversion.py
I thing you can remove the file test_http_conversion.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW we should add one more test for the warning when user still pass list to http task parameter http_params
. we have an example in
dolphinscheduler-sdk-python/tests/tasks/test_sub_workflow.py
Lines 110 to 136 in f82e07d
def test_deprecated_sub_workflow_get_define(mock_workflow_definition): | |
"""Test deprecated task sub_process still work and raise warning.""" | |
code = 123 | |
version = 1 | |
name = "test_sub_workflow_get_define" | |
expect_task_params = { | |
"resourceList": [], | |
"localParams": [], | |
"processDefinitionCode": TEST_SUB_WORKFLOW_CODE, | |
"dependence": {}, | |
"conditionResult": {"successNode": [""], "failedNode": [""]}, | |
"waitStartTimeout": {}, | |
} | |
with patch( | |
"pydolphinscheduler.core.task.Task.gen_code_and_version", | |
return_value=(code, version), | |
): | |
with warnings.catch_warnings(record=True) as w: | |
from pydolphinscheduler.tasks.sub_process import SubProcess | |
assert len(w) == 1 | |
assert issubclass(w[-1].category, DeprecationWarning) | |
assert "deprecated" in str(w[-1].message) | |
with Workflow(TEST_WORKFLOW_NAME): | |
sub_workflow = SubProcess(name, TEST_SUB_WORKFLOW_NAME) | |
assert sub_workflow.task_params == expect_task_params |
BTW, we have a code style check for our codebase, you could run the command and for how to set tox development you can see in https://github.com/apache/dolphinscheduler-sdk-python/blob/main/CONTRIBUTING.md#automated-testing-with-tox |
And I have commit and change some code to you branch, so you should pull them to your local before you add your change |
@zhongjiajie sir i have made the changes and added some tests as well suggested by you. |
@zhongjiajie sir i have mailed you to connect with you |
@zhongjiajie sir I am waiting for your response |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other LGTM, but it seems you forget to format the code by too -e auto-lint
tests/tasks/test_http.py
Outdated
expect = [ | ||
{"prop": "prop1", "direct": "IN", "type": "VARCHAR", "value": "value1"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we can merge test function test_http_params_transformation
and test_http_params_conversion
into single one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, we can merge test function
test_http_params_transformation
andtest_http_params_conversion
into single one
ok i am merging these 2 test functions and pushing it again in few minutes.
I approval the CI run |
Sorry for the inconvenience i will try to do it now. |
you can run the command and then append one more commit this this PR |
@zhongjiajie sir i don't know why but i am not able to setup and run tox command on my local machine, I have tried a lot really sorry for that but still I have done the formatting, linting, styling and all using black and ruff commands manually, please check if it still needs improvement, again sorry for inconvenience. |
I approval CI run. |
@zhongjiajie sir i use mac os. Also sir what to do with these CI run which is failing. |
tax should work with macOS, and you should format http.py files because log said
|
do you install tox first then trying run command |
@zhongjiajie sir I made changes in http.py file using tox , I used different machine with linux as OS , in my mac machine even after installing tox when I was inputting "tox -l" command, it was showing me only version of python that is "312" no file like tox.ini and all, maybe it was some kind of a glitch. |
maybe you can remove the project and try clone from the GitHub again after this PR merged |
@zhongjiajie ok I will try that method, but do you need any more changes in this pull request |
lint still no pass, maybe you can run command
|
@zhongjiajie sir please check it now, i fixed that linting issue and in my machine it is showing me everything fine |
@zhongjiajie sir please provide approval now |
test error for case |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #130 +/- ##
==========================================
+ Coverage 90.86% 90.89% +0.02%
==========================================
Files 64 64
Lines 2354 2361 +7
==========================================
+ Hits 2139 2146 +7
Misses 215 215
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi @HarshitNagpal29 I add and fix some tests in 3a22ec0 for the @patch(
"pydolphinscheduler.core.task.Task.gen_code_and_version",
return_value=(123, 1),
) and for case |
Now all CI are green, merging 🎉 thanks for your contribution and looking forward your next contribute |
@zhongjiajie sir i am really grateful that i was able to work on this issue with you and learn lot of new things, i am looking forward to contribute more , can you please suggest some good first issues which i can work upon or maybe some documentation changes in this project or some other. |
Hi @HarshitNagpal29 here are two of issue maybe good and easy to fix
|
…sion
fix: #88
Brief Summary of The Change
Pull Request checklist
I confirm that the following checklist has been completed.
docs/source/config.rst
when you change filedefault_config.yaml
.UPDATING.md
when it is an incompatible change.