Select to view content in your preferred language

g_ESRI_variable is messing up various parts of a function (not just a data path)

156
1
06-12-2024 09:53 AM
DarrenConly
Occasional Contributor

Here is my function before publishing:

 

def get_project_uid(proj_name, proj_type, proj_jur, user_email):
    """Find the project UID in the master table where project name, type, 
    and user email match and it's the most recently-run one"""

    master_fields = [params.logtbl_join_key, params.f_master_tstamp]

    fc_mastertbl = os.path.join(params.log_fgdb, params.log_master)
    fl_mastertbl = 'fl_mastertbl'
    arcpy.MakeFeatureLayer_management(fc_mastertbl, fl_mastertbl)

    sql = f"""{params.f_master_projname} = '{proj_name}' AND {params.f_master_projtyp} = '{proj_type}'
    AND {params.f_master_jur} = '{proj_jur}' AND {params.f_master_email} = '{user_email}'"""
    
    arcpy.management.SelectLayerByAttribute(fl_mastertbl, "NEW_SELECTION", sql)

    df = esri_object_to_df(fl_mastertbl, esri_obj_fields=master_fields, index_field=None)

    if df.shape[0] == 0:
        uid = "UID_NOT_FOUND"
        arcpy.AddWarning(f"No project records found in {fc_mastertbl} where {sql}")
    else:
        uid = df.sort_values(by=params.f_master_tstamp, ascending=False) \
            [params.logtbl_join_key][0]

    return uid

 

 

And here is what the function looks like after publishing:

 

def get_project_uid(proj_name, proj_type, proj_jur, user_email):
    """Find the project UID in the master table where project name, type, 
    and user email match and it's the most recently-run one"""

    master_fields = [params.logtbl_join_key, params.f_master_tstamp]

    fc_mastertbl = os.path.join(params.log_fgdb, params.log_master)
    fl_mastertbl = g_ESRI_variable_1
    arcpy.MakeFeatureLayer_management(fc_mastertbl, fl_mastertbl)

    uis = params.user_inputs
    sql = g_ESRI_variable_2 [params.logtbl_join_key][0] # g_ESRI_variable_2 = " = '"

    return uid

 

 

You see that the function gets mostly cut off starting at the sql =  part. I've read in previous posts (here and here) that g_ESRI_variable will be created when there are external paths that are not registered or local, but this symptom is completely different. It's replacing an f-string that is just a SQL query, not attempting to be a file path.

The only workaround right now is that after publishing I must manually copy/paste in the original function, but I have nearly two dozen GP services that use this function and this is a very clunky workaround that invites future headaches (e.g., forgetting to copy/paste then spending time trying to remember why).

Is there a fix for this?

 

 

0 Kudos
1 Reply
DavidSolari
Occasional Contributor III

If you make "params" a proper function parameter and pass it in every time does that help?

0 Kudos