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

Failure when inspecting reverse OneToOneFields #36

Open
aemdy opened this issue Apr 17, 2015 · 5 comments · Fixed by #42
Open

Failure when inspecting reverse OneToOneFields #36

aemdy opened this issue Apr 17, 2015 · 5 comments · Fixed by #42

Comments

@aemdy
Copy link

aemdy commented Apr 17, 2015

class User(Model):
    meta = OneToOneField(UserMetadata, related_name='user')

class UserMetadata(Model):
    pass

When I try to compare UserMetadata instances, I get the following error:

Exception Type: AttributeError
Exception Value:    
'User' object has no attribute 'all'

It seems that it thinks it is a related manager instead of object.

@jedie
Copy link
Owner

jedie commented Apr 17, 2015

Thanks for reporting this...

have you a more practical example for this constellation?!?

@aemdy
Copy link
Author

aemdy commented Apr 17, 2015

I don't have another example, but is it very simple scenario:

If you have two models, when one (A) of the has a OneToOneField to another (B). Then try to Compare several versions of model B. It will fail on getting values.

Very ugly solution (just to make it work) would be to modify get_reverse_foreign_key method and check, if getattr(obj, str(self.field.related_name)) is a related manager or object (also you should handle case when related object is not given and it raises ObjectDoesNotExist exception).

@frwickst
Copy link

+1 for this

@frwickst
Copy link

@aemdy It seems that you might have found a solution for this problem, do you think you might be able to make a pull request from https://github.com/aemdy/django-reversion-compare/commit/da60d7873bbd8fb212f7f076a68b0b52e297796e? Before doing so it might be a good idea to fix the commit messages and clean up the changes into proper commits but other then that it would be great to get this fixed. I have not tried your code so I'm not 100% it works but please do a PR if it does.

@jedie
Copy link
Owner

jedie commented Jul 22, 2015

v0.5.4 release is out. Has this been fixed?

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 a pull request may close this issue.

3 participants