PyCharm 2019.1.2 Professional Edition: GraphQL breakpoints not hit

Answered

When I start the debug session, breakpoints in the initialization code are hit fine.  When I use GraphiQL to post data for queries or mutations, none of the breakpoints are hit.

I turned on debugging in PyCharm, and the following is the output after starting the debug session and posting data for a mutation (where-in the breakpoint was NOT hit):

 

/home/brad/.virtualenvs/microservice-amazon-advertising/bin/python /snap/pycharm-professional/132/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 42385 --file /home/brad/github/microservice-amazon-advertising/project/main.py
Using Cython speedups
Unable to load jupyter_debug plugin
Executing file /home/brad/github/microservice-amazon-advertising/project/main.py
arguments: ['/home/brad/github/microservice-amazon-advertising/project/main.py']
PYDEVD_FILTER_LIBRARIES False

Started in multiproc mode

('Connecting to ', '127.0.0.1', ':', '42385')
('Connected.',)
debugger: received >>99 -1 42527
<<
Received command: ??? 99 -1 42527

Received port 42527

pydev debugger: process 10373 is connecting

('Connecting to ', '127.0.0.1', ':', '42527')
('Connected.',)
debugger: received >>501 1 0.1 UNIX
<<
Received command: CMD_VERSION 501 1 0.1 UNIX

Connected to pydev debugger (build 191.7141.48)
sending cmd --> CMD_VERSION 501 1 @@BUILD_NUMBER@@
debugger: received >>111 3 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None
<<
Received command: CMD_SET_BREAK 111 3 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:26 - func_name:b'get_refresh_token'

debugger: received >>111 7 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None
111 5 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None
101 9
146 11 SHOW_RETURN_VALUES 0
122 13 python-BaseException None None 0 1 0
<<
Received command: CMD_SET_BREAK 111 7 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/main.py - line:21 - func_name:b'init'

Received command: CMD_SET_BREAK 111 5 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:10 - func_name:b'get_refresh_token'

Received command: CMD_RUN 101 9

Received command: CMD_SHOW_RETURN_VALUES 146 11 SHOW_RETURN_VALUES 0

Show return values: False

Received command: CMD_ADD_EXCEPTION_BREAK 122 13 python-BaseException None None 0 1 0

Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f42ad68a710>}

Patching args: ['/sbin/ldconfig', '-p']
Process is not python, returning.
sending cmd --> CMD_PROCESS_CREATED 149 2 <process/>
Suspending at breakpoint in file: /home/brad/github/microservice-amazon-advertising/project/main.py on line 21
sending cmd --> CMD_THREAD_CREATE 103 4 <xml><thread name="MainThread" id="pid_10373_id_139924397102248" /></xml>
sending cmd --> CMD_THREAD_SUSPEND 105 6 <xml><thread id="pid_10373_id_139924397102248" stop_reason="111" message="" suspend_type="frame_eval"><frame id="139924197321008" name="init" file="/home/brad/github/microservice-amazon-advertising/project/main.py" line="21"></frame><frame id="139924356674056" name="&lt;module&gt;" file="/home/brad/github/microservice-amazon-advertising/project/main.py" line="26"></frame><frame id="41223512" name="execfile" file="/snap/pycharm-professional/132/helpers/pydev/_pydev_imps/_pydev_execfile.py" line="18"></frame><frame id="139924263149864" name="run" file="/snap/pycharm-professional/132/helpers/pydev/pydevd.py" line="1147"></frame><frame id="44097384" name="main" file="/snap/pycharm-professional/132/helpers/pydev/pydevd.py" line="1752"></frame><frame id="40139928" name="&lt;module&gt;" file="/snap/pycharm-professional/132/helpers/pydev/pydevd.py" line="1758"></frame></thread></xml>
debugger: received >>114 15 pid_10373_id_139924397102248 139924197321008 FRAME
<<
Received command: CMD_GET_FRAME 114 15 pid_10373_id_139924397102248 139924197321008 FRAME

('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f42ad68a358>')
sending cmd --> CMD_GET_FRAME 114 15 <xml></xml>
debugger: received >>106 17 pid_10373_id_139924397102248
<<
Received command: CMD_THREAD_RUN 106 17 pid_10373_id_139924397102248

[2019-05-16 16:30:53 -0400] [10373] [DEBUG]

Sanic
Build Fast. Run Fast.


[2019-05-16 16:30:53 -0400] [10373] [INFO] Goin' Fast @ http://0.0.0.0:9002
sending cmd --> CMD_THREAD_RUN 106 8 pid_10373_id_139924397102248 -1
('Connecting to ', '127.0.0.1', ':', '42385')
sending cmd --> CMD_PROCESS_CREATED 149 10 <process/>
('Connected.',)
debugger: received >>99 -1 43319
<<
Received command: ??? 99 -1 43319

AttributeError: 'PyDB' object has no attribute 'has_plugin_line_breaks'
Exception ignored in: '_pydevd_frame_eval.pydevd_frame_evaluator.get_bytecode_while_frame_eval'
AttributeError: 'PyDB' object has no attribute 'has_plugin_line_breaks'
PYDEVD_FILTER_LIBRARIES False

('Connecting to ', '127.0.0.1', ':', '43319')
('Connected.',)
debugger: received >>501 1 0.1 UNIX
<<
Received command: CMD_VERSION 501 1 0.1 UNIX

sending cmd --> CMD_VERSION 501 1 @@BUILD_NUMBER@@
debugger: received >>111 3 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None
<<
debugger: received >>111 19 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None
<<
Received command: CMD_SET_BREAK 111 19 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None

Received command: CMD_SET_BREAK 111 3 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 26 get_refresh_token THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:26 - func_name:b'get_refresh_token'

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:26 - func_name:b'get_refresh_token'

IDE_PROJECT_ROOTS ['/home/brad/github/microservice-amazon-advertising']

debugger: received >>111 7 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None
111 5 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None
101 9
146 11 SHOW_RETURN_VALUES 0
122 13 python-BaseException None None 0 1 0
<<
Received command: CMD_SET_BREAK 111 7 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:10 - func_name:b'get_refresh_token'

Received command: CMD_SET_BREAK 111 5 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/main.py - line:21 - func_name:b'init'

Received command: CMD_RUN 101 9

Received command: CMD_SHOW_RETURN_VALUES 146 11 SHOW_RETURN_VALUES 0

Show return values: False

Received command: CMD_ADD_EXCEPTION_BREAK 122 13 python-BaseException None None 0 1 0

debugger: received >>111 21 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None
111 23 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None
122 25 python-BaseException None None 0 1 0
146 27 SHOW_RETURN_VALUES 0
<<
Received command: CMD_SET_BREAK 111 21 python-line /home/brad/github/microservice-amazon-advertising/project/api.py 10 get_refresh_token THREAD None None

Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f42a40ea898>}

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/api.py - line:10 - func_name:b'get_refresh_token'

Received command: CMD_SET_BREAK 111 23 python-line /home/brad/github/microservice-amazon-advertising/project/main.py 21 init THREAD None None

Added breakpoint:/home/brad/github/microservice-amazon-advertising/project/main.py - line:21 - func_name:b'init'

Received command: CMD_ADD_EXCEPTION_BREAK 122 25 python-BaseException None None 0 1 0

Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f42ad68a128>}

Received command: CMD_SHOW_RETURN_VALUES 146 27 SHOW_RETURN_VALUES 0

Show return values: False

IDE_PROJECT_ROOTS ['/home/brad/github/microservice-amazon-advertising']

Patching args: ['/bin/sh', '-c', '/home/brad/.virtualenvs/microservice-amazon-advertising/bin/python /home/brad/github/microservice-amazon-advertising/project/main.py']
Process is not python, returning.
sending cmd --> CMD_PROCESS_CREATED 149 10 <process/>
[2019-05-16 16:30:53 -0400] [10389] [INFO] Starting worker [10389]
sending cmd --> CMD_THREAD_CREATE 103 12 <xml><thread name="MainThread" id="pid_10381_id_139924397102248" /></xml>
2019-05-16 16:31:11,168 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'sql_mode'
2019-05-16 16:31:11,168 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,173 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'lower_case_table_names'
2019-05-16 16:31:11,173 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,177 INFO sqlalchemy.engine.base.Engine SELECT DATABASE()
2019-05-16 16:31:11,177 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,178 INFO sqlalchemy.engine.base.Engine show collation where `Charset` = 'utf8mb4' and `Collation` = 'utf8mb4_bin'
2019-05-16 16:31:11,179 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,181 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS CHAR(60)) AS anon_1
2019-05-16 16:31:11,181 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,183 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS CHAR(60)) AS anon_1
2019-05-16 16:31:11,183 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,184 INFO sqlalchemy.engine.base.Engine SELECT CAST('test collated returns' AS CHAR CHARACTER SET utf8mb4) COLLATE utf8mb4_bin AS anon_1
2019-05-16 16:31:11,185 INFO sqlalchemy.engine.base.Engine ()
2019-05-16 16:31:11,186 INFO sqlalchemy.engine.base.Engine BEGIN (implicit)
2019-05-16 16:31:11,188 INFO sqlalchemy.engine.base.Engine INSERT INTO account (account_id, refresh_token) VALUES (%s, %s)
2019-05-16 16:31:11,188 INFO sqlalchemy.engine.base.Engine ('account_id_3', '')
2019-05-16 16:31:11,189 INFO sqlalchemy.engine.base.Engine ROLLBACK
[2019-05-16 16:31:11 -0400] - (sanic.access)[INFO][127.0.0.1:41650]: POST http://0.0.0.0:9002/graphql 200 43
[2019-05-16 16:31:16 -0400] [10389] [DEBUG] KeepAlive Timeout. Closing connection.
9 comments
Comment actions Permalink

Did you put a breakpoint in Python code?
PyCharm takes all the database related features from DataGrip and there is no debugging feature. Similar https://youtrack.jetbrains.com/issue/DBE-424

>When I start the debug session, breakpoints in the initialization code are hit fine.

Here you are referring to Python code, right?

0
Comment actions Permalink

Yes I am referring to the python code (ie, the initialization code).

I wasn't referring to debugging the database (sorry for the confusion there).

So to restate, when I call a query or mutation, the code is not hit.  Here's a little code to show what I'm referring to:

 

class Mutation(graphene.ObjectType):
create_account = CreateAccount.Field()

I have a breakpoint on the 2nd line and it gets hit when the debug session starts.  Now here is the mutate method:

class CreateAccount(relay.ClientIDMutation):
class Input:
code = graphene.String(required=True)

account = graphene.Field(AccountType)

@classmethod
def mutate_and_get_payload(cls, _root, _info, code, _client_mutation_id=None):
try:
account = None
logging.log(logging.INFO, f"mutate code hit. code = {code}")
return CreateAccount(account=account)
except exc.DBAPIError:
return CreateAccount(account=None)

The logging statement works correctly, but breakpoints aren't hit inside this method.  Here is the log from a single run of the mutation:

DEBUG:sanic.root:

Sanic
Build Fast. Run Fast.


INFO:sanic.root:Goin' Fast @ http://0.0.0.0:9002
INFO:sanic.root:Starting worker [4624]
INFO:root:mutate code hit. code = test_code
INFO:sanic.access:
DEBUG:sanic.root:KeepAlive Timeout. Closing connection.

Let me know if anything else is needed for investigation.  Thanks

 

 

0
Comment actions Permalink

Hmm, I couldn't reproduce it. Perhaps I did something wrong somewhere.

Would it be possible to share the whole project or its relevant part for reproducing? If so, please upload it to https://uploads.services.jetbrains.com/ zipped and let me know the name of the file.
We guarantee its privacy.

0
Comment actions Permalink

Entire project zipped and uploaded. 

microservice-amazon-advertising.zip
0
Comment actions Permalink

Thanks!
So you put a breakpoint inside of mutate_and_get_payload method?
I don't see any logging coming from that method when running main.py

Could you please specify where you expect this method to be initialized?

I ran profiling for main.py and there is no such method.

0
Comment actions Permalink

Yes I put the breakpoint in mutate_and_get_payload.  I also put a breakpoint in the following locations: 

init()
Query(graphene.ObjectType)
Mutation(graphene.ObjectType)

Those breakpoints are hit successfully.

In order to get the mutate method to be hit, you have to debug the project and then open http://0.0.0.0:9002/graphql.  Once opened insert the following mutation query in the UI:

mutation {
createAccount(input:{code: "test_code"}) {
account {
accountId,
refreshToken
}
}
}

After running that mutation, you'll see the logging statement in output.log.

0
Comment actions Permalink

Hmm,

The method is still not initialized from what I can see. I even added a simple print('test') before try block, but it wasn't printed after opening http://0.0.0.0:9002/graphql in the browser and running the query.

Perhaps I miss something?

0
Comment actions Permalink

I just added a print statement to the top of the mutate_and_get_payload method and got the statement output in the PyCharm Debugger Console.  Not sure why your environment isn't working.  Did you put a breakpoint in init() and was it hit upon startup of the debugging session?

0
Comment actions Permalink

Yes, just like you said PyCharm was also able to hit breakpoints on the following lines:

init()
Query(graphene.ObjectType)
Mutation(graphene.ObjectType)

I'll try some more. Please let me know if you find something out in the meantime.

0

Please sign in to leave a comment.