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

ngsi_v2 tutorials are deprecated #255

Closed
WaltherTrgovac opened this issue Mar 2, 2024 · 6 comments · Fixed by #259
Closed

ngsi_v2 tutorials are deprecated #255

WaltherTrgovac opened this issue Mar 2, 2024 · 6 comments · Fixed by #259
Assignees
Labels
bug Something isn't working

Comments

@WaltherTrgovac
Copy link
Collaborator

Describe the bug
ngsi_v2 tutorials consist of exercises and solutions. Solutions use methods that are deprecated (pydantic and json methods).

To Reproduce
Executing exercise 3 solutions to exercise 7 produces various errors.

Expected behavior
Solutions should run properly.

Screenshots

Environment (please complete the following information):

Additional context
Mostly TypeErrors are causing the errors that are easy to fix. There are also some PEP 8 errors occuring.

@WaltherTrgovac WaltherTrgovac added the bug Something isn't working label Mar 2, 2024
@WaltherTrgovac WaltherTrgovac self-assigned this Mar 2, 2024
Copy link

github-actions bot commented Mar 2, 2024

Branch 255-ngsi_v2-tutorials-are-deprecated created!

@WaltherTrgovac
Copy link
Collaborator Author

WaltherTrgovac commented Mar 7, 2024

I am running into problems at exercise 5. There is a method imported from pydantic called parse_file_as. This method does not exist in version 2 of pydantic anymore. What I tried to do is use the method validate_python. This method takes a loaded json file as a parameter. I have done that, but then I keep running into other errors that might be connected to the deprecated method.
Here is the attempt.

@WaltherTrgovac
Copy link
Collaborator Author

I am running into problems at exercise 5. There is a method imported from pydantic called parse_file_as. This method does not exist in version 2 of pydantic anymore. What I tried to do is use the method validate_python. This method takes a loaded json file as a parameter. I have done that, but then I keep running into other errors that might be connected to the deprecated method. Here is the attempt.

I have made some progress here. It might be, that this is the correct implementation but now other problems appear. It seems that SERVICE_PATH is playing a role. After you change the service path in exercise 4 to something unique and you try to execute exercise 5, you have to have the same service path which makes sense. The following error appears: requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http://localhost:4041/iot/devices.
Interestingly, if you try to execute the same file (exercise 5) again, you get the following error: pydantic_core._pydantic_core.ValidationError: 1 validation error for list[ServiceGroup] 0.cbHost Input should be a valid URL, relative URL without a base [type=url_parsing, input_value='None', input_type=str]. And if you try to execute the file again, the second error keeps appearing. So the first error appears only after single execution and not again. If you want it to appear again, you would need to execute exercise 4 with changed service path.

@djs0109
Copy link
Contributor

djs0109 commented Mar 12, 2024

@WaltherTrgovac thanks for the contribution! Could you make a pull request (PR) for this branch? We can better discuss the detail implementation or solution under the PR

@hannahgoerigk
Copy link

Hey, I am currently trying to follow these tutorials and stumbled upon the same issues you've already mentioned here. I am currently stuck on e5, as I get the same parsing error you have.
I got some additional issues I'd like to add here as there are inconstistencies between the tasks and solutions (minor fixes):

e4_iot_thermal_zone_sensors.py:

  • Missing Import in line 34: from filip.clients.ngsi_v2 import ContextBrokerClient, IoTAClient
  • Missing Code at the end of the exercise: starts at 264 in e4_iot_thermal_zone_sensors_solution.py

e5_iot_thermal_zone_control.py:

  • Missing Import in line 47: from filip.models.base import DataType, FiwareHeader

I haven't continued with the other exercises yet. If I find more inconsistencies, I will post them here

@tstorek
Copy link
Collaborator

tstorek commented Mar 12, 2024

@WaltherTrgovac validate_python is most likely not the function you used. In the newer evrsion of pydantic you need to parse the json yourself and then, e.g. use the validate_model function. If the *.json contains a list you need to convert to a list of dicts.

Subseeunetly, you can create a list of models usige e.g. list-comprehension

@WaltherTrgovac WaltherTrgovac linked a pull request Mar 12, 2024 that will close this issue
djs0109 added a commit that referenced this issue Apr 30, 2024
…cated

fix: ngsi v2 tutorials are deprecated (#255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants