Comments (8)
According to https://docs.python.org/3/library/os.html#os.listdir:
The list is in arbitrary order
If it were truly random, then I would disagree that forcing it into a deterministic order could break things (because it would already break every now and again due to random behaviour. At least now it would be either breaking all the time or not break at all).
But the order is not truly random, it depends on the underlying OS. This means, that when installing the same app on a different OS or even after an OS upgrade, things could break potentially.
I feel like I would rather have a consistent behavior than one determined by the OS on which the app happens to be running.
@ankush how about implementing a feature toggle? A flag in the hooks.py "import_fixture_in_sorted_order" or something like that? Then people aware of the issue could start implementing the toggle and the behavior would be documented.
from frappe.
There is one major possibility of breaking things when porting where random order that used to work will now no longer work because of deterministic order. - @ankush
If it were truly random, then I would disagree that forcing it into a deterministic order could break things (because it would already break every now and again due to random behaviour. - @Tom-Finke
I agree with Tom. I cannot think of any situation where randomly importing fixtures is okay for a Custom App. But importing in a predefined way is somehow worse.
Fixtures were never supposed to be "insert any random document to DB from code"... for that you have to write code and handle all the scenarios. @ankush
Yet the framework allows this. It does not error or stop you. If fixtures were not supposed to do this, then the developers shouldn't have allowed for it. No one is asking for new features: just improvements to what already exists today.
In your case only, you're inserting "Item" as a fixture, which was NEVER intended use for this.
Item
is a user/site-specific doctype that will almost never have to be hardcoded in code. @ankush
What "intended use"? Where documented? I've never read any article that says some DocTypes are acceptable for fixtures, but others are not.
Assuming for a moment that's true. If fixtures are not the answer, then what is? What other feature(s) can people use to automatically handle data updates when deploying? The key word here is automatically. Certainly data updates can be performed manually after a code deployment. No one is questioning that.
I agree with @tgraupne that this seems trivial: take an unsorted array and make it sorted. 🤷♂️
Will this solve every possible use case of fixtures? No. Of course not. You are correct @ankush that some data imports will still be problematic.
That doesn't mean fixtures cannot, or should not, be made incrementally better than they are today.
from frappe.
Fixtures have long outlived their intended use. Custom field, property setters, custom doctypes can all be inserted without any dependency on each other. In absence of dependencies they'll just not work. Fixtures were never supposed to be "insert any random document to DB from code"... for that you have to write code and handle all the scenarios.
In your case only, you're inserting "Item" as a fixture, which was NEVER intended use for this. Item
is a user/site-specific doctype that will almost never have to be hardcoded in code.
from frappe.
Imho, this is a trivial basic function of custom apps
It's far from "trivial".
Export Item, Customer, Company, Sales order, sales invoice, delivery note and try writing a sane importer for it without assuming anything about those doctypes.
Even a known import order doesn't really work because ERPNext can require invoice before delivery sometimes and delivery before invoice some other times and both can be parallel inserted too in some other case. 🤷
Fixtures should just be limited to very dumb static data.
from frappe.
There is one major possibility of breaking things when porting where random order that used to work will now no longer work because of deterministic order 😬 main reason why I held off port.
TBH fixtures have very limited use case. When you start requiring order of insertion you're already entering into "code" from "data", so you might as well just write code instead.
Most complex apps that customize core behaviours eventually do this.
from frappe.
TBH fixtures have very limited use case. When you start requiring order of insertion you're already entering into "code" from "data", so you might as well just write code instead.
🤔 I find this statement quite interesting, because I don't "require order". I was only hoping, that fixtures exported with bench
can actually be imported again.
Imho, this is a trivial basic function of custom apps and bench export-fixtures
. What other option do people have who need to package and ship Custom Fields and a handful of initialisations?
This all started, trying to find one working approach which enables developers to develop locally, checkin and deploy their changes to testing environments and eventually to production. And after hours of research and discussions the result was, a custom app and fixtures are your best bet. 🤷♀️
from frappe.
@ankush I really appreciate your time and knowledge sharing, but I have a hard time following.
Why are you talking about all those things? I have never mentioned those and I don't understand how they are relevant?
Export Item, Customer, Company, Sales order, sales invoice, delivery note and try writing a sane importer for it without assuming anything about those doctypes.
You say,
Fixtures should just be limited to very dumb static data.
And this is all I want to do, I just want to import 2 Item Groups
and 2 basic Items
which belong to those groups. And even this simple import of static data does not work, because frappe is complaining that the Item Groups
do not exist when trying to import the Items
. That is all I want to achieve.
You say,
In your case only, you're inserting "Item" as a fixture, which was NEVER intended use for this. Item is a user/site-specific doctype that will almost never have to be hardcoded in code.
Maybe there is a misunderstanding, I am not trying to "import" a new DocType. I am just trying to import documents of the type: DocType Item
.
You say,
Fixtures have long outlived their intended use.
And then you mention Custom fields etc. If fixtures are not intended to be used to do exactly this, why is the official frappe documentation still stating this:
And above all, discuss.frappe.io and the whole ERPNext-Youtube is full of people using Custom Apps and Fixtures to deploy and ship Custom Fields to Standard DocTypes. If those approaches are just plain wrong, I believe hundreds of people would be very happy to find out what the intended feature to use would be.
How can people make Changes and Create Custom Fields and add very dumb static data and at the end, ship everything as Code?
from frappe.
I use Fixtures to set up Workflows, Roles, Email templates, Price lists (just their existence, not any prices) and a few property setters (but not many of the latter any more), but nothing more complicated than that.
As an alternative to Fixtures, presumably any custom data needed by a custom app can be handled by a combination of install.py for new installations and patches for existing ones?
from frappe.
Related Issues (20)
- Add Support for Number Card to Count Records in Reports
- Support Editable Report Cells HOT 2
- Default app is not shown after log out HOT 1
- Communications don't show base64 image properly
- Workspace sidebar doesn't get auto refreshed on selecting workspaces during setup
- Breaking change or regression: Quick Entry form now calls form setup without initializing fields HOT 1
- images in the discuss.frappe website not loading HOT 2
- Unable to export data using Data Import Tool
- (v16) calls to form's `setup` event in Quick Entry lead to errors HOT 6
- Filters for Webhook HOT 1
- pip semantic-version conflict HOT 1
- Magic pixel link throwing ModuleNotFound error HOT 7
- [App switcher] The selected app is not correctly highlighted
- Login redirects to app switcher (/apps) instead of desk (/app) as of 15.39.0 HOT 3
- Infinite Loop in Form Load With Table Fields and mandatory_depends_on/read_only_depends_on HOT 2
- Brand Logo not being removed from email footer after clearing
- Doc Mapper with better merging algorithms HOT 3
- frappe website search not working, impacting frappe wiki search feature
- XSS Security Risk HOT 6
- Table in web form not translate
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from frappe.