-
Notifications
You must be signed in to change notification settings - Fork 33
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
ManyToManyField inside tracked field breaks field_value function #10
Comments
Just typing out some notes to help me wrap my head around this. So this seems to happen under these circumstances: Model A tracks a field that is a foreign key to Model B. And Model B has a many-to-many relationship with Model C. |
Hey @ljle, I have a branch to test this issue. Take a look at the test here. It actually passes just fine. :\ I noticed your |
Hey @grantmcconnaughey, I checked out to the branch, ran the tests and it is indeed passing. Here is the model: class OSD_StatusMotive(models.Model):
status_type = models.ForeignKey(OSD_Status)
motive = models.ForeignKey(OSD_Motive)
class Meta:
db_table = 'osd_statusmotive'
def __unicode__(self):
return "(estado: %s) - (motivo: %s) - %s" % (self.status_type.name,
self.motive,
self.motive.entity.model_name) Btw, I noticed that |
Ugh, even with a class Window(models.Model):
pass
class Building(models.Model):
windows = models.ManyToManyField(Window, through='BuildingWindows')
class BuildingWindows(models.Model):
building = models.ForeignKey(Building)
window = models.ForeignKey(Window)
class Restaurant(models.Model):
building = models.ForeignKey(Building)
field_history = FieldHistoryTracker(['building']) and here is the test: def test_field_history_works_with_foreign_key_that_has_many_to_many(self):
window = Window.objects.create()
building = Building.objects.create()
BuildingWindows.objects.create(building=building, window=window)
restaurant = Restaurant.objects.create(building=building)
self.assertEqual(FieldHistory.objects.count(), 1)
history = FieldHistory.objects.get()
self.assertEqual(history.object, restaurant)
self.assertEqual(history.field_name, 'building')
self.assertEqual(history.field_value, building)
self.assertIsNotNone(history.date_created) |
Yes, I think I left Django out of requirements because it gets installed in |
The only thing left I can think of is to run your tests again and spit out the JSON in |
Sure. I ran your test and it passes. I added a class RestaurantType(models.Model):
name = models.CharField(max_length=50)
class Restaurant(models.Model):
name = models.CharField(max_length=50)
restaurant_type = models.ForeignKey(RestaurantType)
building = models.ForeignKey(Building)
field_history = FieldHistoryTracker(['building', 'restaurant_type', 'name']) When I access [{"model": "tests.restaurant", "pk": 1, "fields": {"restaurant_type": 1}}]
[{"model": "tests.restaurant", "pk": 1, "fields": {"name": "McDonalds"}}] When I access
|
Thanks, @ljle. Now that we have a failing test I can start to dig into why it is happening. Let me know if you come up with anything, and thanks a lot for reporting this! |
No problem, @grantmcconnaughey. If I come up with anything I'll update the issue. |
Consider the following models:
As you can see the field status_type in OKB_Article has a ManyToManyField called motive.
If I'm tracking the status_type field, the field_value function only works for that field; I can't access the field_value of any other field, it throws a DeserializationError mentioning the status_type field even though I'm not accesing it. See the screenshot where I reproduce and mimick what the field_value function does inside an ipdb debugger:
However, this only happens when I'm tracking said field. If I remove it from the FieldHistoryTracker list, I can access all the other fields without a problem.
I'm using the latest version of Django 1.9.x along with the latest Python 2.7.x on Linux.
The text was updated successfully, but these errors were encountered: