Variables not appearing in pm.sample_posterior_predictive

Using the model below, I expect to be able to use az.plot_ppc to be able to see if the models is able to predict values for travel_time_obs. Yet when I go to run that command, I am told that other var names are not present. Code and error message posted below.

KeyError: 'var names: "[\'alarms_obs\' \'latent\'] are not present" in dataset'

second_model = pm.Model()



with second_model:
    #constants
    A = pm.Data('A', 61.13) #miles square
    n = pm.Data('n', 33) #number of engine companies
    
    # Priors for unknown model parameters
    α = pm.Uniform('α',0,50) #pm.HalfNormal('α',sigma=100) #not a lot known about this varibale as it would requier experimental data 0
    β = pm.Uniform('β',1,10)  #pm.HalfNormal('β',sigma=100) #not a lot known about this varibale as it would requier experimental data 2.2
    γ = pm.HalfNormal('gamma',sigma = 1) # has to be a fractional exponent according to Kolesar [1975] .3
    λ = pm.Gamma('λ', alpha=1, beta=1)
    alarms_obs = pm.Poisson('alarms_obs', mu= λ, observed = incident_data['alarms_per_hour'])
    #sigma_y = pm.HalfNormal('sigma_y', sigma=100)
    ϕ = pm.HalfNormal('sigma_y', sigma=1) #shape parameter for Wald distribution is likely to be less than 1 given the sharp peak seen in the  travel time data



    #ES
    mu = pm.Normal('mu', mu=0,sigma=1)
    alpha_raw = pm.Normal("alpha_raw", mu=0, sigma=0.1)
    alpha_w = pm.Deterministic("alpha_w", pt.exp(alpha_raw))
    beta_n_w = pm.Deterministic("beta_n_w", pt.exp(mu / alpha_w))
    beta_w = pm.Deterministic("beta_w", (beta_n_w * incident_data['service_time'].max())-(1/3600))
    
    # Sampling distribution of observed service times
    latent = pm.Weibull('latent',alpha=alpha_w, beta=beta_n_w, observed = experiment)

    ES = pm.Deterministic('ES', beta_w*pt.gamma(1 + 1/alpha_w))

    # Expected value of travel_time
    ET = pm.Deterministic('ET',α + β*(A/(n-λ*ES))**γ)

    # Sampling distribution of observed travel times
    travel_time_obs = pm.Wald('travel_time_obs', mu=ET, phi=ϕ, observed=incident_data['travel_time']+ (1/60)) 
    #pm.Normal("Y_obs", mu=ET, sigma=sigma_y, observed=incident_data['travel_time'])
  
    trace2 = pm.sample(draws=4000, chains=4, nuts_sampler='nutpie')

with second_model:
    trace2.extend(pm.sample_prior_predictive(draws=50))
    idata_posterior = pm.sample_posterior_predictive(trace2, var_names=['travel_time_obs', 'latent', 'alarms_obs'],
                                                     return_inferencedata=True,
                                                     extend_inferencedata=True,
                                                     predictions=False)
az.plot_ppc(idata_posterior, data_pairs={'travel_time_obs': 'travel_time_obs'}, num_pp_samples=100)

Sorry about the late reply, can you share what you get when you print idata_posterior.observed_data and idata_posterior.posterior_predictive? If you can do the same at the different at the different stages of trace2 it would be even better.

There might be something wrong with some of the conversion steps, it looks like travel_time_obs is missing from one of these two groups. Not sure why this is happening though.