1

How careful do I have to be when modifying a Blender file through bpy?

Is it possible, through any part of the the Python API/console, to permanently alter a file's data in a way that is impossible to undo through the GUI?

Is the fact that it is or isn't possible by explicit design, or is it due to lucky concidence or unlucky bugs?

Will Chen
  • 1,607
  • 8
  • 21
  • Running scripts have crashed blender millions of times, corrupted a handful (if that) of times. – batFINGER Feb 27 '21 at 21:03
  • Since it's using Python, everything is possible, not only corrupting a .blend file, but also the operating system (hence the warning when a script is run automatically or a driver has a scripted "slow" expression using Python interpreter. – Markus von Broady Feb 27 '21 at 21:53
  • @MarkusvonBroady Okay, yes. But I specifically mean through bpy, and via the data structures and methods therein. I'm not going to call open().write() or os.system() with unsanitized inputs, for example, but I might recurse through bpy.data and randomly reassign, call, or delete objects' properties and methods with other objects' properties and _RNA_UI values. – Will Chen Feb 27 '21 at 22:29
  • 1
    Just to make sure it's clear, bpy is not contained like a sandbox, so theoretically a random change to bpy.data can modify one of methods, which in turn can do the harm. This is also what I meant by "Since it's Python" - you can freely modify methods and properties of all objects. Damaging an OS without ill intent is unlikely, but possible, and corrupting a file is more likely - but how likely exactly depends largely on your coding style and any answer other than "it's possible" I think would be opinionated and therefore a bad fit on this site. – Markus von Broady Feb 27 '21 at 22:39
  • @MarkusvonBroady I believe it's possible to reasonably answer this question without relying on opinion. For example, any examples of past addons or known bugs would form an answer to the affirmative, while developer responses to such cases would indicate whether it is meant to be possible. – Will Chen Feb 27 '21 at 23:01
  • @MarkusvonBroady In referring to "bpy" and the "file's data" in my original question, I indicate that my interest is not on monkey-patched OS-level calls that then have some chance of damaging the file on-disk. Rather, my concern is whether the internal structure of the file, as opened and stored in memory in Blender and then written back to disk by Blender, can be altered by bpy itself in a way that cannot be undone through the GUI. – Will Chen Feb 27 '21 at 23:06
  • @MarkusvonBroady Besides, I'm not convinced your examples of modifying the API even apply. As I understand it, such changes do not persist when the file is saved and reloaded, so that doesn't meet the irreversibility criteria I put in my question. And even if it did lasting damage by going through the os/filesystem or some other means, any damage that occurs because you modified the API itself is by definition not damage that was done by the original API. – Will Chen Feb 27 '21 at 23:07
  • @MarkusvonBroady I'm asking whether the bpy API itself has any features that could cause file and scene corruption, and whether it's meant to— Not whether you can modify said API to add on such features. – Will Chen Feb 27 '21 at 23:07
  • 4
    My first comment was in regard to making all sorts of attempts to bend blender to my will using the API, and have IIRC corrupted about about 2 files in 15 years. The most common corruption error seen is "Missing Blocks" caused by computer crashing mid save. See https://blender.stackexchange.com/questions/87582/missing-dna-block This site has >80K questions. Questions related to corrupt blend files are way rarer than those about AMD gpu issues. Agree somewhat wit @MarkusvonBroady re as question is stated it lends to yes... eg can sink the unsinkable Titanic by running it into an iceburg – batFINGER Feb 28 '21 at 07:47
  • @batFINGER Cool. Thanks for the lead. I do think this question has the issue of asking to prove a negative, and hence inviting unhelpful answers— But I do not think the central point of API safety and design is itself opinionated or vague.

    The files that you corrupted— Do you remember if they were through operations in the API itself (I.E. corrupted data in-memory, messed up DNA/RNA/link/what-have-you, which was then written out to disk), or if it was through OS, process, or file system-level errors (E.G. crash while saving)?

    – Will Chen Feb 28 '21 at 16:52

0 Answers0