* perf: `Document` objects without circular references
Circular references are usuallly considered bad for GC, avoiding them
since they don't seem to be necessary.
* fix: explicitly convert to weakref
Related: https://github.com/frappe/frappe/issues/23475
Likely caused by: https://github.com/frappe/frappe/pull/22110
Because run_doc_method passes doc from client to server side, we end up
setting values for what is a "virtual field", this is why it finds some
value and not re-evaluate it.
IMO there are only mild breaking ways of fixing this:
1. Virtual fields should always be computed.
2. Virtual fields should not be set when init-ing the arguement. (e.g. from doc.set APIs )
The problem is same as mutable defaults. Container type class attributes
are mutable and shared between all objects.
```python
class CLS:
attr = {}
...
a = CLS()
b = CLS()
a.attr is b.attr # => True
```
Problem:
document.save() throws "Object is not scriptable exception" when fetching values from virtual doc.
Root cause:
```python
# ....
if frappe.get_meta(doctype).get("is_virtual"):
values = frappe.get_doc(doctype, docname) <--- Document is not scriptable.
.as_dict()
# ....
def set_fetch_from_value(self, doctype, df, values):
fetch_from_fieldname = df.fetch_from.split(".")[-1]
value = values[fetch_from_fieldname] <--- Tries to access value by key and throws "Object is not scriptable" exception
```
Solution:
```python
if frappe.get_meta(doctype).get("is_virtual"):
values = frappe.get_doc(doctype, docname).as_dict() <--- Makes the document scriptable.
```
* Util get_permitted_fields checks for valid columns instead of planned logic
* Remove virtual field from dict if not in permitted fields
* Remove reliance on sentinel object _DOC_DELETED_ATTR
When a TextEditor field contains only an image, while checking for
content, HTML tags are stripped off including the only image.
This change adds a loose but explicit check for img tag.
### BREAKING CHANGE
#### Datetime, Date and Time fields will always be cast to respective objects in `setattr`, this will ensure uniformity while accessing the values, no more `getdate`, `get_datetime`, `to_timedelta` wrapper.
- While importing data, the framework does check for `set_only_once`.
- In normal case scenarios, this will work flawlessly since most date fields might not be set_only_once.
- But in Subscription, the date field is set to `set_only_once` and in `after_insert`, `document.save` is called, and while doing so, `set_only_once` is checked [here](1944a547f9/frappe/model/document.py (L566)).
-This works fine if the data imported is in the correct format.
- If the date's data is not in the correct format, the framework throws an error.
- for eg `06-02-2022 00:00:00 != 06-02-2022`
- fixes [Issue/#15370](https://github.com/frappe/frappe/issues/15370)
> no-docs