Needs work
Project:
Relation
Version:
7.x-1.x-dev
Component:
API
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Nov 2011 at 08:42 UTC
Updated:
8 Oct 2014 at 19:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mikran commentedYou can't create nodes of types that don't exist so imo this goes as a bug and should apply to relation_save() as well.
Comment #2
mikran commentedAttached patch adds type validation to relation_save() plus relation_type_load() $types param is now marked as optional.
Comment #3
mikran commentedComment #4
mikran commented#3: type_validation_with_tests-1345648-3.patch queued for re-testing.
Comment #6
mikran commentedreroll
Comment #7
mikran commentedreroll
Comment #8
mikran commentedrelation_endpoint_field_validate() already does this:
So instead of previous patch got to figure out why the code above is not working. For now it looks to be same bug as #1597770: Required fields are not attached on relation_save
Comment #9
naught101 commentedAttached patch adds four tests, that try to create invalid relations: a relation with a non-existent relation type, a relation with invalid endpoints, a relation with a required field missing, and a relation with a field with invalid data. (The later two are for #1597770: Required fields are not attached on relation_save).
My understanding is that these should all fail at present, although if the field validation is working, then the latter two will only fail because the expected message is wrong. Let's see how it goes.
Comment #10
naught101 commentedComment #12
naught101 commentedAgain!
Comment #14
naught101 commentedMOAR
Comment #16
naught101 commentedOk, this should do it. Fails properly if it succeeds!
Comment #18
naught101 commentedOk, notifiees, I'm gonna stop bugging you after this one - I figured out what I was doing wrong with my local tests, and this one is correct.
First 3 tests are failing because the relations are created, the fourth one is failing because the relation is being created, but there's a an SQLSTATE error due to the incorrect field data. So validation is failing in all cases.
Commited to the relation_validation_tests branch, incase anyone wants to work on it while I'm asleep. Good night!
Comment #20
naught101 commentedClosed #1277762: Need general way to validate relations as a duplicate
Comment #21
naught101 commentedThere's potentially reasons why it might make sense to create an invalid relation, so relation_create should probably either throw a warning if the relation is invalid, or happily create invalid relations, while relation_save should throw a error.
Comment #22
dpiRelation_create shouldnt be so strict on any passed default values, except for relation_type, which I think should throw an exception.
On save, the type can be rechecked to ensure it exists. Or throw invalid type exception.
If the relation does not have the correct number of endpoints, or incorrect type endpoints, then an integrity exception should be thrown.
Comment #23
naught101 commentedI think create probably shouldn't do any checking. I can imagine a UI where the endpoints are selected first, and then on the next page, all possible matching relation types are given as options. Sounds unlikely, but it may have some kind of use..
Comment #24
mikran commentedIssue title was bad. There is no reason to validate anything in relation_create, but broken relations shouldn't get stored to database.
Comment #25
dpiRight... relation_save
Comment #26
naught101 commentedThere is no
relation_validate():)Comment #27
mikran commented#2160525: "Field validation failed." - relations are not saved closed as duplicate of this. But now we have mixed arguments
should relation_save() validate more stuff or less? At the very least we need to add tests that verify what's the intended behaviour.