How to debug server side code

86 views
Skip to first unread message

Fabio Lenzarini

unread,
Oct 10, 2024, 11:59:12 AM10/10/24
to Jam.py Users Mailing List
Hello everyone,
unfortunately I never have a lot of time to devote to Jam.Py (I work very hard on D365 F&O).. but some timeI experiment and carry on some SW that helps me in my work.
When we have to write code that works a lot on data, we always have the dilemma:
do I write it client-side with JS or server-side in Python?
well, if we have to manipulate a lot of data, the server side is much closer to the data and definitely faster..
But it is also true that JS code is easier to debug....

Today I tried for the umpteenth time to debug the server code.

And I succeeded!
With Visual studio code I open the file “server.py” from the project folder d the file “wsgi.py” in the Jam.py folder.
I put a breackpoint at line 747 “def server_func...” where there is “result = func(obj, *params). then I debug ‘server.py’.

On the browser I open the application and run the function that executes the server-side code to debug... et voila!
I can see on Visual studio code my server funcion and I debug every line of code!

Another step is done!

ciao
Fabio


Dean D. Babic

unread,
Oct 10, 2024, 9:04:00 PM10/10/24
to Jam.py Users Mailing List
Nice!
Thanks for sharing

Dean D. Babic

unread,
Oct 15, 2024, 11:07:58 PM10/15/24
to Jam.py Users Mailing List
Hi Fabio, 

just tried to do this but no luck.
Could you record a video?

Cheers

Fabio Lenzarini

unread,
Oct 16, 2024, 4:30:58 AM10/16/24
to Jam.py Users Mailing List
Hi Drazen, it was my intention to do that...
By the way I realized that there is a problem in updating the displayed sources, they are corrected only if there is an error..

ciao
Fabio

Fabio Lenzarini

unread,
Nov 6, 2024, 5:04:00 AM11/6/24
to Jam.py Users Mailing List
Hi, the video are more than 200MB and I can't load it..

Drazen Babic

unread,
Nov 6, 2024, 5:05:59 AM11/6/24
to Fabio Lenzarini, Jam.py Users Mailing List
Google drive can handle this imo

Cheers

--
You received this message because you are subscribed to a topic in the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jam-py/k7H4bHLpKL8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jam-py+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jam-py/2c15a98f-6ca8-4e91-a4a9-e3fef095cfa1n%40googlegroups.com.

Fabio Lenzarini

unread,
Nov 6, 2024, 7:09:26 AM11/6/24
to Jam.py Users Mailing List
debug.pdf

Dean D. Babic

unread,
Oct 2, 2025, 4:04:50 AM10/2/25
to Jam.py Users Mailing List
Hi, 

if someone is interested, to debug server side, including Server Module content changes, add this in bold to wsgi.py:

    def server_func(self, obj, func_name, params):
        result = None
        error = ''
        func = getattr(obj, func_name)
        if func:
            result = func(obj, *params)
            if consts.SHOW_SELECT_SQL:
                print('-- Server code start --')
                print(func_name, params)
                print('-- Server code end --')
        else:
            raise Exception('item: %s no server function with name %s' % (obj.item_name, func_name))
        return result, error

If Show Select SQL is ON on Parameters, this will also show server side. Than, we can use similar format
as in items.py class SQLFormatter.

Cheers

D.

Fabio Lenzarini

unread,
Mar 4, 2026, 7:46:39 AMMar 4
to Dean D. Babic, Jam.py Users Mailing List
Hi all, new version to debug server side code with VS code.

change server_func function on wsgi.py file adding "sem" code:

    def server_func(self, obj, func_name, params):
        result = None
        error = ''


## seb.debug.sn                        
       
        import os, importlib.util

        # 1. Scrivi server_code su file fisico
        server_code = getattr(obj, 'server_code', None)
        module_name = getattr(obj, 'module_name', None)

        if server_code and module_name:
            debug_dir = os.path.join(os.getcwd(), '_debug_funcs')
            os.makedirs(debug_dir, exist_ok=True)
           
            safe_name = obj.module_name.replace('.', '_')
            debug_file = os.path.join(debug_dir, f'{safe_name}.py')
           
            with open(debug_file, 'w') as f:
                f.write(obj.server_code)
           
            # 2. Carica dal file (VS Code lo vede)
            spec = importlib.util.spec_from_file_location(obj.module_name, debug_file)
            mod = importlib.util.module_from_spec(spec)
            spec.loader.exec_module(mod)
       
        # 3. Esegui — ora puoi mettere breakpoint direttamente nel file _debug_funcs/...py
            func = getattr(mod, func_name, None)
        else:
## seb.debug.en

                     
            func = getattr(obj, func_name)
           
        if func:
            result = func(obj, *params)
        else:
            raise Exception('item: %s no server function with name %s' % (obj.item_name, func_name))
        return result, error

now, start server.py by VS code and set a breakpoint

image.png

when the code pause, open the new file created by the script for your function

image.png

and set your breakpoint

image.png

then, "continue" F5 and the debug stop on the breakpoint

image.png


You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jam-py/5c41f12a-7711-443b-8ceb-9e960e6db0d5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages