| 1334 | |
| 1335 | |
| 1336 | def _populate_full( |
| 1337 | context, |
| 1338 | row, |
| 1339 | state, |
| 1340 | dict_, |
| 1341 | isnew, |
| 1342 | load_path, |
| 1343 | loaded_instance, |
| 1344 | populate_existing, |
| 1345 | populators, |
| 1346 | ): |
| 1347 | if isnew: |
| 1348 | # first time we are seeing a row with this identity. |
| 1349 | state.runid = context.runid |
| 1350 | |
| 1351 | for key, getter in populators["quick"]: |
| 1352 | dict_[key] = getter(row) |
| 1353 | if populate_existing: |
| 1354 | for key, set_callable in populators["expire"]: |
| 1355 | dict_.pop(key, None) |
| 1356 | if set_callable: |
| 1357 | state.expired_attributes.add(key) |
| 1358 | else: |
| 1359 | for key, set_callable in populators["expire"]: |
| 1360 | if set_callable: |
| 1361 | state.expired_attributes.add(key) |
| 1362 | |
| 1363 | for key, populator in populators["new"]: |
| 1364 | populator(state, dict_, row) |
| 1365 | |
| 1366 | elif load_path != state.load_path: |
| 1367 | # new load path, e.g. object is present in more than one |
| 1368 | # column position in a series of rows |
| 1369 | state.load_path = load_path |
| 1370 | |
| 1371 | # if we have data, and the data isn't in the dict, OK, let's put |
| 1372 | # it in. |
| 1373 | for key, getter in populators["quick"]: |
| 1374 | if key not in dict_: |
| 1375 | dict_[key] = getter(row) |
| 1376 | |
| 1377 | # otherwise treat like an "already seen" row |
| 1378 | for key, populator in populators["existing"]: |
| 1379 | populator(state, dict_, row) |
| 1380 | # TODO: allow "existing" populator to know this is |
| 1381 | # a new path for the state: |
| 1382 | # populator(state, dict_, row, new_path=True) |
| 1383 | |
| 1384 | else: |
| 1385 | # have already seen rows with this identity in this same path. |
| 1386 | for key, populator in populators["existing"]: |
| 1387 | populator(state, dict_, row) |
| 1388 | |
| 1389 | # TODO: same path |
| 1390 | # populator(state, dict_, row, new_path=False) |
| 1391 | |
| 1392 | |
| 1393 | def _populate_partial( |