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

Update metrics on transfer/owner change #810

Merged
merged 3 commits into from Feb 27, 2017
Merged

Update metrics on transfer/owner change #810

merged 3 commits into from Feb 27, 2017

Conversation

noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Feb 27, 2017

This PR fix metrics not being updated after transfer for initial owner (organization or user):

  • factorize the owning behavior into a tested mixin, ensuring all owned items have the same behavior and allowing to detect owner change
  • split the big models/__init__.py into modules (models/queryset.py, models/document.py)
  • test and fix transfer acceptation => fix metrics not being updated after transfer

Tests require #809 to pass

'owner',
'organization',
],
'queryset_class': OwnedQuerySet,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use that? Maybe inheriting from Owned.meta['queryset_class'] is possible but quite ugly :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Mongoengine behavior: child classes inherit this queryset (at least used in tests), unless this is explicitely overriden.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

import logging

from blinker import signal

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same coding style used in every module: import grouped by packages if not builtin.


def owned_pre_save(sender, document, **kwargs):
'''
Owned pre_save handler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that comment is useful? (redundant with method name?)


def owned_post_save(sender, document, **kwargs):
'''
Owned post_save handler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -99,10 +101,89 @@ def test_request_transfer_to_same_organization(self):
self.assert_transfer_started(dataset, org, org, comment)


class TransferAcceptTest(TestCase, DBTestMixin):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -49,6 +46,8 @@ def __init__(self, app=None):
self.ValidationError = ValidationError
self.ObjectId = ObjectId
self.DBRef = DBRef
self.Owned = Owned
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why we need these two lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows, as every other db mixins, to be used as db.Owned and db.OwnedQuerySet.
db act as a facade pattern everywhere.

'resources.id',
'resources.urlhash',
],
] + db.Owned.meta['indexes'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if db.Owned.INDEXES is easier to understand. Here it looks to be dynamic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But where does it come from ?
The meta['indexes'] the only way (I know) to get the mixin default indexes.
It relies on mongoengine default (documented) behavior in which meta is a dictionary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I thought it was udata-related. My bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;)

def owned_pre_save(sender, document, **kwargs):
'''
Owned pre_save handler
Need to fetch original owner before the new one erase it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for on_owner_change to transfer metrics too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand :/

'''
Owned post_save handler
Dispatch the `Owned.on_owner_change` signal
once the document has been saved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

including the previous owner

Copy link
Member

@davidbgk davidbgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍


class DomainModel(UDataDocument):
'''Placeholder for inheritance'''
pass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless pass ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just extracted from models/__init__.py as it was. I think the only usecase is isinstance(document, DomainModel)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, why not directly isinstance(document, UDataDocument)?

@noirbizarre noirbizarre merged commit 6564aa8 into opendatateam:master Feb 27, 2017
@noirbizarre noirbizarre deleted the update-metrics-on-transfer branch February 27, 2017 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants