How to specify the order in which fixtures are to be imported

Hello

I’m developing a custom app in v13.32.

I’ve amended hooks.py with the fixtures I need for testing on a production instance and then use bench export-fixtures to export and persist testing data to the fixtures directory.

Then on the production environment, I use bench get-app and then bench install-app to instantiate the app. However, during bench install-app all the fixtures are also imported, but not in any specific order, causing an error. How can I impose an order to the importing of fixtures since there’s an implicit precedence amongst them such as for Role and Role Profile and a subsequent User having these roles or profiles?

Any workaround will also be much appreciated !

1 Like

Hi Eugene,
did you find a solution for this issue? I’m having the same problem: I assumed that during app installation the fixtures would be imported in the order specified by the fixtures array, but that’s not the case.

I hope you could share your experiences with us, because it would be time consuming to write an import method when there’s already a feature to do that with “bench install-app …”.

Regards, Fernando G.

Hi @fergarcia

No, I’m afraid not.

However, I do an initial bench install-app without any fixture files in the fixture directory. I then do multiple bench migrate invocations, each time adding more fixture files to the fixtures directory. It’s a trial-and-error process to determine in which order to add the fixtures. In general, a Role and Role Profile has to be imported before a User, etc.

As a matter of interest, most fixtures will only be re-imported if the modification date in the JSON is more recent than what it was when it was originally imported. Hence I do not bother to remove successfully imported fixture files from the fixtures directory.

Let me know whether you follow a similar method.

2 Likes