atlassian-api / atlassian-python-api

Atlassian Python REST API wrapper
https://atlassian-python-api.readthedocs.io
Apache License 2.0
1.29k stars 643 forks source link

flask use gevent.monky makes advanced_mode is true #1254

Open zystudios opened 9 months ago

zystudios commented 9 months ago

I have a strange problem.

If I don't use monkey.patch_all, everything works fine

When I use monkey.patch_all in flask, advanced_mode changes to True

from gevent import monkey
monkey.patch_all()
from atlassian import Jira

my_jira = Jira(url, username, password)
my_jira.issue(key="xxxxx")
my_jira.user(username="xxxx")

I'm calling both methods to get the issue and user.

Getting user returns <Response [200]> not a json.

I traced the source code. then I found in rest_client.py

image

 def get(
        self,
        path,
        data=None,
        flags=None,
        params=None,
        headers=None,
        not_json_response=None,
        trailing=None,
        absolute=False,
        advanced_mode=False,
    ):
        """
        Get request based on the python-requests module. You can override headers, and also, get not json response
        :param path:
        :param data:
        :param flags:
        :param params:
        :param headers:
        :param not_json_response: OPTIONAL: For get content from raw request's packet
        :param trailing: OPTIONAL: for wrap slash symbol in the end of string
        :param absolute: bool, OPTIONAL: Do not prefix url, url is absolute
        :param advanced_mode: bool, OPTIONAL: Return the raw response
        :return:
        """
        response = self.request(
            "GET",
            path=path,
            flags=flags,
            params=params,
            data=data,
            headers=headers,
            trailing=trailing,
            absolute=absolute,
            advanced_mode=advanced_mode,
        )
        print(self.advanced_mode)  # True
        print(advanced_mode) # False
        if self.advanced_mode or advanced_mode:
            return response
        if not_json_response:
            return response.content
        else:
            if not response.text:
                return None
            try:
                return response.json()
            except Exception as e:
                log.error(e)
                return response.text

self.advanced_mode is True, so return is raw format, not json

if I don't use monkey.patch_all, then self.advanced_mode = False

Is this a bug? How do I return the json format, I didn't find a way to set the self.advanced_mode

Thanks very much

gonchik commented 9 months ago

Hi! as I see we have to check the following expression if self.advanced_mode: instead a full one

zystudios commented 8 months ago

Hi! as I see we have to check the following expression if self.advanced_mode: instead a full one

thanks, I'm guessing that monkey.patch_all made the function execution at the same time, causing self.advanced_mode not to change in time