Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ManyToManyFields on concrete models #53

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

paravoid
Copy link
Contributor

In the concrete models, add ManyToManyFields between Network and Facility/IXLan, and InternetExchange and Facility.

Intermediate models already exist (NetworkFacility, NetworkIXLan and InternetExchangeFacility respectively) and these are being used as "through" models with Django's many-to-many field.

Effectively, this does not really change the schema, but provides forward and reverse managers to go from one of these objects to the next. So for example, one can use ixp.fac_set.all() to list all facilities for an exchange, or fac.ix_set.all() to do the inverse.

Note that this change really makes the definitions of the InternetExchangeFacility and InternetExchangeFacilityBase models moot, as they're "through" models with no additional fields, and if they were absent, Django would create the intermediate tables in the database itself. However, avoid not being removed in this change to minimize the amount of changes and risk involved here.

Finally, although a more descriptive "facilities" or "networks" would be preferrable in the author's opinion, the new fields are named <shorthand>_set (fac_set, ix_set, ixlan_set) to match existing conventions.

As far as I can tell, this doesn't work. self.ixfac_set is a manager
object, which is not iterable (one would have to do self.ixfac_set.all()
to iterate through it).
In the concrete models, add ManyToManyFields between Network and
Facility/IXLan, and InternetExchange and Facility.

Intermediate models already exist (NetworkFacility, NetworkIXLan and
InternetExchangeFacility respectively) and these are being used as
"through" models with Django's many-to-many field.

Effectively, this does not really change the schema, but provides
forward and reverse managers to go from one of these objects to the
next. So for example, one can use ixp.fac_set.all() to list all
facilities for an exchange, or fac.ix_set.all() to do the inverse.

Note that this change really makes the definitions of the
InternetExchangeFacility and InternetExchangeFacilityBase models moot,
as they're "through" models with no additional fields, and if they were
absent, Django would create the intermediate tables in the database
itself. However, avoid not being removed in this change to minimize the
amount of changes and risk involved here.

Finally, although a more descriptive "facilities" or "networks" would be
preferrable in the author's opinion, the new fields are named
"<shorthand>_set" (fac_set, ix_set, ixlan_set) to match existing
conventions.
@paravoid
Copy link
Contributor Author

The CI check here is red herring (in one of the hosts it failed on a assert backend.last_change(models.Organization) == now_t for a 1 second difference). If someone can re-trigger, it should pass.

@vegu
Copy link
Contributor

vegu commented Jul 26, 2021

This seems to break peeringdb sync once installed

$ peeringdb sync
Syncing to https://www.peeringdb.com/api
Updating resources: org fac net ix ixfac ixlan ixpfx netfac netixlan poc
Fetching & updating all: org
Updates to be processed: 0
Fetching & updating all: fac
Updates to be processed: 0
Fetching & updating all: net
Updates to be processed: 123
Traceback (most recent call last):
  File "/home/vegu/sandbox/pdbclient/venv/bin/peeringdb", line 8, in <module>
    sys.exit(main())
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/cli.py", line 67, in main
    return handler(config=cfg, **vars(options))
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/commands.py", line 19, in _wrapped
    r = func(*a, **k)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/commands.py", line 250, in handle
    client.update_all(rs, since)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_update.py", line 68, in update_all
    ctx.sync_resource(r, since=since)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_tasks_sequential.py", line 76, in _wrapped
    return _consume_task(gen)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_tasks_sequential.py", line 57, in _consume_task
    item = gen.send(r)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_tasks_sequential.py", line 38, in gather
    yield from job
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_update.py", line 199, in sync_row
    fetched, dangling = _sync.extract_relations(B, res, row)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_sync.py", line 89, in extract_relations
    _, subrow = _get_subrow(row, fname, field)
  File "/home/vegu/sandbox/pdbclient/venv/lib/python3.9/site-packages/peeringdb/_sync.py", line 68, in _get_subrow
    subrow = row[key]
KeyError: 'fac_set'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants