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
Getting notified when a resource's DataStore data changes #4558
Comments
Overriding the datastore_create, _upsert and _delete actions is one option. I like to use triggers on the datastore database to detect changes because this is slow and unreliable when done on the python side. I've thought about adding a standard datastore trigger that would collect the # rows created, updated and deleted with each action and pass that back to the actions. Would that be the sort of thing you need? |
@wardi My interest in this area stems from stadt-karlsruhe/ckanext-extractor#13: currently, ckanext-extractor doesn't handle DataStore-backed resources very well, and one reason is that some ways of creating those don't trigger the usual I wouldn't need any fancy features for solving this issue (e.g. statistics about the number of rows affected), a simple hook for reacting to any change would probably be enough. However, I don't have much experience with using the DataStore, so there maybe an approach that, in addition to solving my problem, is better suited to other use cases. In the meantime I'll see whether overriding |
hello wardi, I would be interested in what you describe in your speech: I would like to insert a trigger to detect when a resource is added to the ckan, have you already faced the thing? could you kindly give me some advice? thank you |
As of CKAN 2.8, the DataStore API functions don't mix well with the
IResourceController
interface. Things that I noticed:Calling
datastore_create
on an existing resource (i.e. when passingresource_id
) does not triggerIResourceController.after_update
. In contrast, callingdatastore_create
to create a new resource (i.e. passingresource
) does triggerIResourceController.after_create
.Calling
datastore_upsert
does not triggerIResourceController.after_update
Calling
datastore_delete
does not triggerIResourceController.after_update
This means that it's currently impossible to reliably get notified when a resource's data in the DataStore changes.
Now I'm not sure whether
IResourceController
would be the right way to perform these notifications, since technically, the actual resource metadata doesn't change -- only the associated DataStore data does. So a DataStore-specific interface would probably be more appropriate.There exists the
IDatastore
interface (which, although documented in the code, doesn't seem to be mentioned in the official docs), but it is intended to alter DataStore queries before they are executed.In my opinion, we should
IResourceController
to mention thatThe text was updated successfully, but these errors were encountered: