Skip to content

Conversation

rafinhaLQ
Copy link
Contributor

@rafinhaLQ rafinhaLQ commented Dec 4, 2023

Related Issue or bug

When running the generated API on docker would throw this exception:
pydantic.errors.PydanticUserError: A non-annotated attribute was detected

And also, I wasn't able to access the API running on docker.

Did not found any open issue on this problems, I found the problems when I was using pycaret.

Describe the changes you've made

I changed only pycaret\internal\pycaret_experiment\tabular_experiment.py.

There was 4 modifications:

  • I added an empty line at the end of the generated Dockerfile and requirements.txt, for good practices;
  • Added pydantic==1.10.0 requirement at generated requirement.txt.
    It was necessary because airflow version it's compatible with pydantic version 1.10. If you don't specify the version it will use pydantic version < 2.0.
    You could also solve that error without specifying pydantic version changing the requirement pycaret to pycaret[full]. But it would make your docker image size significantly bigger. That's why I choose to follow this approach. In my tests I made version 1 with pycaret[full] and version 2 with pydantic==1.10.0. Here's the result:
    image
  • I also added apt-get clean at RUN on the generated docker file.
    This will remove the cache after install packages, not storing an index, reducing the size of your docker image and speeding up your deployments.
  • And finally. I changed the CMD on generated dockerfile to ["uvicorn", "{API_NAME}:app", "--host", "0.0.0.0", "--port", "{PORT}"].
    When running fast api on a container you need to tell Uvicorn to not care about the incoming host IP with option --host 0.0.0.0. Without it you will not be able to access your API outside Docker.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, local variables)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

I built docker images using python:3-8-slim to python:3.11-slim, in each version of python I built images with and without specifying pydantic version, and with and without telling Uvicorn to not care about incoming host IP.

Describe if there is any unusual behaviour of your code(Write NA if there isn't)

NA

Checklist:

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

Screenshots

Original Updated
image image

@celestinoxp
Copy link
Contributor

celestinoxp commented Dec 6, 2023

Hi, why pydantic at version 1 instead of using the latest version?
Try using the latest version and change anything necessary.

@rafinhaLQ
Copy link
Contributor Author

@celestinoxp If you use pydantic latest version ( < 2.0 ), it will result on a PydanticUserError, cause airflow version used is only compatible if you use a version >= 1.10.0 and < 2.0.0.
You could also use pycaret[full] instead of specifying the pydantic version cause pycaret full will already bring a compatible pydantic version. But I choose to specify the version to make the docker image smaller and faster to build. I put a photo with this two solutions on the pull request description to show it.

@Yard1
Copy link
Member

Yard1 commented Dec 9, 2023

Thanks for the PR! Can we set pydantic to < 2.0.0 to loosen the restriction a little?

@rafinhaLQ
Copy link
Contributor Author

@Yard1 Thank you for the feedback! I think it makes much more sense just setting pydantic to < 2.0.0, I made some tests in my machine and it seems to work fine

@Yard1 Yard1 merged commit ad1d426 into pycaret:master Dec 9, 2023
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.

3 participants