Skip to content

Conversation

@ankitdas13
Copy link
Contributor

@ankitdas13 ankitdas13 commented Aug 5, 2025

Fix deprecation warning on runtime

Warning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html

import pkg_resources
from pkg_resources import DistributionNotFound
version = pkg_resources.require("razorpay")[0].version
except (PackageNotFoundError, DistributionNotFound, NameError): # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching multiple exceptions ensures robustness, but consider logging a warning if version retrieval fails, to aid client debugging.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catching NameError is thoughtful for edge-case compatibility, but it may also mask unrelated issues. Consider logging or at least adding a comment for future maintainers.

# DistributionNotFound: pkg_resources couldn't find the package
# NameError: in case the exception classes aren't defined due to import issues
pass
return version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning an empty string on exception is safe, but would it be more useful to return None or log a warning for SDK users who may rely on version info?

Copy link
Contributor Author

@ankitdas13 ankitdas13 Aug 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@razorpay-sanjib Returning None would break the string formatting in User-Agent header. but we can add warning like this

except:
   warnings.warn(
    "Could not detect razorpay package version. Using fallback version. "
    "This may indicate an installation issue.",
    UserWarning,
     stacklevel=4
   )
return version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check this commit

Copy link
Contributor

@razorpay-sanjib razorpay-sanjib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ankitdas13 ankitdas13 added the TestingNotRequired TestingNotRequired label for BVT label Sep 16, 2025
@ankitdas13 ankitdas13 merged commit 7b8f0ed into master Sep 17, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

TestingNotRequired TestingNotRequired label for BVT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants