Federation: Backlink problems with database constraints
Currently backlinks are sent with only @type
and @id
set on the object
Currently federated models do not support nullable fields (#167 (closed))
However an error is thrown if a model has a field with the unique constraint set (such as LDPUser from djangoldp_account). If validation is skipped then the UNIQUE constraint fails on the database level and an IntegrityError
is thrown. I haven't tested but I'm sure that this error would be raised by CHECK constraints as well
To workaround this for the demonstration I've committed a cardinal sin
if self.backlink_created:
self.email = str(uuid.uuid4()) + "@startinblox.com"
This could be generalised so that placeholder data is stored on any backlink model. This would be unnoticeable clientside but is obviously horrendous serverside
The alternative solution which comes to mind is to pass fields with the object. As the LDPSerializer now renders only @id
for distant objects I considered that this could default to all fields except for those omitted from serializer_fields
(sensitive information)
However there are considerations with the alternative as well:
- unique fields (such as email) will be effectively unique across all instances. So if I register an email with HD Paris I can't use the same email in a different account on HD Nantes
- the sender does not know about the receiver's constraints, e.g. there might be a CHECK constraint enforced on HD Nantes which isn't on HD Paris
- the receiver may have NOT NULL and UNIQUE fields stored on the model which the sender doesn't store at all
Updates:
- #351 may be a possible solution