Search code examples
pythongoogle-cloud-platformgoogle-bigqueryreturn-value

Message not retaining values set in function


I am initializing a bigquery_datatransfer_v1.types.ScheduleOptions message and setting its values based on logic in a function. I have tried including the values in the constructor of the message, and setting them after initializing the message. Neither have worked, and the "set" methods listed in the documentation are not recognized when I try to use them.

Below is the current code where I try to initialize then set the values of the message, and the output it produces:

Why are the values in the message none?

Function:

def build_schedule_options(disable_auto_scheduling_flag): 
    config = bigquery_datatransfer_v1.types.ScheduleOptions()     
    print(start_dt.isoformat())
    staggered_start_time = Timestamp().FromDatetime(start_dt)
    config.disable_auto_scheduling = disable_auto_scheduling_flag
    config.start_time = staggered_start_time
    
    print(config.start_time)
    ...
    print(config.start_time, config.end_time, config.disable_auto_scheduling,)

Output:

2023-09-08T12:43:57.755482
None
None None False

Documentation for bigquery_datatransfer_v1.types.ScheduleOptions: Link


Solution

  • Did you include the necessary imports before running the script? It seems that you haven't correctly assigned the values. The required imports should be:

    from google.protobuf.timestamp_pb2 import Timestamp
    from google.cloud import bigquery_datatransfer_v1