sabuhish / fastapi-mail

Fastapi mail system sending mails(individual, bulk) attachments(individual, bulk)
https://sabuhish.github.io/fastapi-mail/
MIT License
673 stars 82 forks source link

update UploadFile function to be compatible with starlette>=0.24 #177

Closed Divyessh closed 1 year ago

Divyessh commented 1 year ago

Update the UploadFile function to make it compatible with newer versions of starlette.

-> Remove the content_type argument (which was earlier being passed to UploadFile) file fastapi_mail/schemas.py MessageSchema -> Update dependencies in pyproject.toml

sabuhish commented 1 year ago

Hi thanks for the PR, seems like you have not updated the lock file, could you update the dependencies also?

Divyessh commented 1 year ago

Thank You @sabuhish , I have updated the poetry lock and dependencies.

sabuhish commented 1 year ago

Thanks, @Divyessh for this commit. I understand you want to make it compatible with starlette, the feature has not been removed, it has been taken into another function. Every file we send has different content types, I believe we must support specifying the content type.

The feature was discussed here; https://github.com/encode/starlette/pull/1413/files

Divyessh commented 1 year ago

@sabuhish , The reason for this PR was that right now, if we install fastapi==0.92, it will install starlette==0.25, which is not compatible with the present stage of fastapi-mail==1.2.5. So the latest version of fastapi-mail is right now not compatible with latest version of fastapi or starlette

Divyessh commented 1 year ago

@sabuhish Here is a minimal reproducible example:

Install the packages

pip install fastapi
pip install fastapi-mail

Create a file.txt file Create the file test.py and enter following:


from fastapi_mail import MessageSchema

message = MessageSchema( subject="Test", recipients=["test@gmail.com"], body="Test", subtype="html", attachments=["file.txt"], )

If we run the `test.py` file, we will face the following error:

pydantic.error_wrappers.ValidationError: 1 validation error for MessageSchema attachments UploadFile.init() got an unexpected keyword argument 'content_type' (type=type_error)

sabuhish commented 1 year ago

I understand your concern, but not agree with removing the feature of content_type. it supports via headers, you can old feature by passing headers https://github.com/encode/starlette/blob/master/starlette/datastructures.py#L452

Divyessh commented 1 year ago

@sabuhish, No problem, I have added the content-type to the headers instead. Thanks

sabuhish commented 1 year ago

Thanks, @Divyessh, now it looks fine actually.