Portkey-AI / portkey-python-sdk

Build reliable, secure, and production-ready AI apps easily.
https://portkey.ai/docs
MIT License
46 stars 17 forks source link

[Bug]: cashfree-pg sdk is giving error with portkey-ai package #247

Open harshit-ambitio opened 23 hours ago

harshit-ambitio commented 23 hours ago

Contact Details

harshit@ambitio.in

What happened?

After installing portkey in a Django project which is using cashfree-pg as the payment gateway , it started throwing error of pydantic.

Version

0.1.xx (Default)

Relevant log output

from .views import initiate_payment,get_package_details,validate_and_apply_coupon,get_transaction_status,status_webhook,installement_payment_webhook,proPaymentPublic,get_upcoming_installment
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/payments/views.py", line 19, in <module>
    from cashfree_pg.models.create_order_request import CreateOrderRequest
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/__init__.py", line 23, in <module>
    from cashfree_pg.api_client import ApiClient
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/api_client.py", line 57, in <module>
    import cashfree_pg.models
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/models/__init__.py", line 47, in <module>
    from cashfree_pg.models.create_offer_request import CreateOfferRequest
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/models/create_offer_request.py", line 27, in <module>
    from cashfree_pg.models.offer_validations import OfferValidations
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/models/offer_validations.py", line 24, in <module>
    from cashfree_pg.models.offer_validations_payment_method import OfferValidationsPaymentMethod
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/models/offer_validations_payment_method.py", line 36, in <module>
    class OfferValidationsPaymentMethod(BaseModel):
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/cashfree_pg/models/offer_validations_payment_method.py", line 58, in OfferValidationsPaymentMethod
    one_of_schemas: List[str] = Field(OFFERVALIDATIONSPAYMENTMETHOD_ONE_OF_SCHEMAS, const=True)
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/pydantic/fields.py", line 997, in Field
    raise PydanticUserError('`const` is removed, use `Literal` instead', code='removed-kwargs')
pydantic.errors.PydanticUserError: `const` is removed, use `Literal` instead

Code of Conduct

sujay6801 commented 23 hours ago

facing the same issue

csgulati09 commented 23 hours ago

Hey!

What version of pydantic are you folks on?

harshit-ambitio commented 23 hours ago

@csgulati09 we are using cashfree-pg===4.3.0 as our payment gateway , and cashfree is internally install pydantic-1.10.19

csgulati09 commented 23 hours ago

Even in our SDK we have 1.10.0 as the bare minimum requirement

install_requires =
...
  pydantic>=1.10.0
...

I think this should not be a major problem to resolve, can you check the current version of pydantic by running pip show pydantic

harshit-ambitio commented 23 hours ago

yes it's 1.10.9.

What i feel it is doing is we already had cashfree-pg package , but installing portkey-ai , it changed pydantic version to 2.x.x and that was breaking cashfree-pg. But if i uninstall both and install portkey sdk first then cashfree , then cashfree is ignoring the pydantic installation.

Edit : Sorry it will throw error once we start using it with openAI clients.

Error Log:


<module>
    from portkey_ai.api_resources.client import AsyncPortkey, Portkey
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/portkey_ai/api_resources/client.py", line 6, in <module>
    from portkey_ai.api_resources.base_client import APIClient, AsyncAPIClient
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/portkey_ai/api_resources/base_client.py", line 22, in <module>
    from portkey_ai.api_resources.apis.create_headers import createHeaders
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/portkey_ai/api_resources/apis/create_headers.py", line 3, in <module>
    from portkey_ai.api_resources.utils import get_portkey_header
  File "/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/portkey_ai/api_resources/utils.py", line 8, in <module>
    from pydantic import BaseModel, field_validator
ImportError: cannot import name 'field_validator' from 'pydantic' (/Users/harshitrathi/Documents/Ambitio/ambitio-backend/env/lib/python3.10/site-packages/pydantic/__init__.cpython-310-darwin.so)
csgulati09 commented 23 hours ago

What you can also try is to install a specific version for pydantic. This will override the existing version of the package. This can be done by running pip install pydantic===a.b.c

(Though, pydantic is encouraging users to move to 2.x.x of their package.)

harshit-ambitio commented 22 hours ago

Yes , although in that cashfree-pg breaks , still if i have pydantic version of 1.10.19 , portkey-ai sdk should not break right , still it breaking , you can see in the above error log.

csgulati09 commented 22 hours ago

Got it! Just one more thing, the above error that you posted, that came after you set pydantic version to 1.10.19?

harshit-ambitio commented 22 hours ago

Yes @csgulati09

csgulati09 commented 22 hours ago

Cool. Planning to release a fix by today EoD. I have identified the issue, looking for a way to fix in a better way.

harshit-ambitio commented 21 hours ago

Cool , Thank you @csgulati09

csgulati09 commented 13 hours ago

Hey! The PR is raised for this. Will be doing final checks and then merging it.

harshit-ambitio commented 3 hours ago

Okay , let me know when it's deployed.