You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some hooks in Resource to allow easy customization: before_save_instance, etc.
I want to take an extract file and use it to create some parent models as part of the same import process. The best way for me to do this, is to call the import_data method for the other ModelResources immediately before I start processing the rows (so that I am already inside the transaction management, if required). At the moment, I have to copy and paste the entire import_data method into my Resource: it would be better if we had something like:
ifuse_transactionsisTrue:
# when transactions are used we want to create/update/delete object# as transaction will be rolled back if dry_run is setreal_dry_run=Falsetransaction.enter_transaction_management()
transaction.managed(True)
else:
real_dry_run=dry_runinstance_loader=self._meta.instance_loader_class(self, dataset)
self.before_import(dataset, real_dry_run)
forrowindataset.dict:
Similarly, some of my customizations work by overriding import_obj, but this can more difficult than necessary because we don't know whether we are in a dry run or not.
This could be solved by adding dry_run to the method signature of import_obj and passing it when you call it from import_data.
Would those changes be acceptable? If they would, I'll prepare a pull request.
The text was updated successfully, but these errors were encountered:
I think that transferring dry_run is the best way for now, because if we are using transaction management we need to pass it as False to the lower-level code even if it is True at the top-level.
There are some hooks in
Resource
to allow easy customization:before_save_instance
, etc.I want to take an extract file and use it to create some parent models as part of the same import process. The best way for me to do this, is to call the
import_data
method for the other ModelResources immediately before I start processing the rows (so that I am already inside the transaction management, if required). At the moment, I have to copy and paste the entireimport_data
method into myResource
: it would be better if we had something like:Similarly, some of my customizations work by overriding
import_obj
, but this can more difficult than necessary because we don't know whether we are in a dry run or not.This could be solved by adding
dry_run
to the method signature ofimport_obj
and passing it when you call it fromimport_data
.Would those changes be acceptable? If they would, I'll prepare a pull request.
The text was updated successfully, but these errors were encountered: