Skip to content

flask use gevent.monky makes advanced_mode is true #1254

Open

Description

@zystudios

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

Activity

  1. gonchik commented on Oct 3, 2023

    @gonchik
    Member

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

  2. zystudios commented on Oct 10, 2023

    @zystudios
    Author

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions