@@ -382,13 +382,14 @@ def __instance_creator__(self, obj):
382382 #
383383 return GomApiInstance (obj ['id' ])
384384
385- def encode (self , req ):
385+ def encode (self , req , caller ):
386386 from gom .__network__ import EncoderContext , DecoderContext
387387
388388 with EncoderContext () as context :
389389 string = json .dumps (req , cls = Encoder .CustomJSONEncoder , encoding_context = context )
390390
391- string = gom .__common__ .__connection__ .request (Request .API , {'json' : string })
391+ string = gom .__common__ .__connection__ .request (
392+ Request .API , {'json' : string , 'caller' : caller if caller != None else "" })
392393
393394 with DecoderContext () as context :
394395 reply = json .loads (string , cls = Encoder .CustomJSONDecoder , decoding_context = context )
@@ -399,7 +400,7 @@ def encode(self, req):
399400 return reply ['result' ]
400401 raise KeyError ()
401402
402- def call_function (self , module , function , args , kwargs ):
403+ def call_function (self , module , function , args , kwargs = {}, caller = None ):
403404
404405 #
405406 # Script-to-script call shortlink. This way, various value conversions can be skipped and shared memory for
@@ -414,16 +415,16 @@ def call_function(self, module, function, args, kwargs):
414415 'params' : args
415416 }
416417
417- return self .encode (request )
418+ return self .encode (request , caller )
418419
419- def call_method (self , instance , method , args ):
420+ def call_method (self , instance , method , args , caller = None ):
420421 request = {
421422 'instance' : instance ,
422423 'call' : method ,
423424 'params' : args
424425 }
425426
426- return self .encode (request )
427+ return self .encode (request , caller )
427428
428429
429430__encoder__ = Encoder ()
@@ -437,12 +438,20 @@ def __call_function__(*args, **kwargs):
437438 '''
438439 frame = inspect .currentframe ().f_back
439440
441+ # Extract the original function caller, i.e., the script in which the api function was written
442+ # The distinction to the executed script is important for some api functions in the context of shared environments
443+ # There scripts from other apps can be imported and some api functions resolve the calls based on the app (e.g. settings)
444+ parent = frame .f_back
445+ caller = ""
446+ if parent != None :
447+ caller = parent .f_code .co_filename
448+
440449 module = inspect .getmodule (frame ).__name__
441450 prefix = 'gom.api.'
442451 if module .startswith (prefix ):
443452 module = module [len (prefix ):]
444453
445- return __encoder__ .call_function (module , frame .f_code .co_name , args , kwargs )
454+ return __encoder__ .call_function (module , frame .f_code .co_name , args , kwargs , caller )
446455
447456
448457class Object :
0 commit comments