Skip to content
This repository has been archived by the owner on Jan 18, 2020. It is now read-only.

Models with empty One-to-One fields not included in results #328

Open
sgithens opened this issue Sep 8, 2016 · 3 comments
Open

Models with empty One-to-One fields not included in results #328

sgithens opened this issue Sep 8, 2016 · 3 comments

Comments

@sgithens
Copy link
Contributor

sgithens commented Sep 8, 2016

I've had an issue with one of our datasets including django models with OneToOneFields. If a OneToOne field in a root result is null/empty in the database, then that item is excluded from the results. I would expect that this result would still be included, but that the columns/fields with an empty OneToOne relationship would just be empty in the returned Harvest results.

Currently, I am fixing this in our dataset by occasionally running a job that goes through the root model items, and if any of it's OneToOne fields are null, populating them with a related instance whose fields are all empty.

@sgithens
Copy link
Contributor Author

sgithens commented Sep 8, 2016

I'm looking at creating a few unit tests for this, and I see the avocado/tests/models.py where I would put a 1:1 model and field, and I'm trying to determine which sub tests model would be the appropriate one to put some harvest queries to look at the number returned and if the empty 1:1 relationships are being excluded. It looks the best place might be tests/cases/models/tests.py?

Any thoughts on the best location for tests that are verifying the number of harvest rows returned based on the employee models and fixtures?

@murphyke
Copy link
Member

Hi Steve, why don't you put it in that spot, and if Byron has a better idea at review time, he'll let you know. At this point, he and you are the best judges of the right location ;-).

@bruth
Copy link
Contributor

bruth commented Sep 16, 2016

@sgithens A one-to-one field as far as Django is concerned is:

similar to a ForeignKey with unique=True, but the “reverse” side of the relation will directly return a single object.

If you do have null entries, then I am not sure what the behavior would actually be. My guess is that when Avocado attempts to format the data, a DoesNotExist exception is thrown which may screw with the output.

Do you mind changing the field to a ForeignKey to see if you see results in the client? This does not require any changes to the database schema.

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

No branches or pull requests

3 participants