-
-
Notifications
You must be signed in to change notification settings - Fork 96
Executing blocks with malformed results section erases org file contents #486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I face a similar symptom regularly but only on commands that fails and triggers error / warnings.
So a good starting point on any investigation would be:
Sorry that I do not have time right now to look further into this but I shall investigate more on it later since it affects me a lot. |
Could you give an example where Emacs-Jupyter causes the It would be great if you could provide a minimum working example Org file with example source blocks that can reproduce your problem. I am aware of the scenario that you mention, but evaluating source blocks with Emacs-Jupyter should always create valid Org documents. |
I have also been seeing these issues but haven't had a chance to debug further and create a minimum working example. I suspect the org-element--cache issues may be related to to the way jupyter handles ansi colors as I still see inconsistent behavior for error outputs that have escape characters to color them. |
@nnicandro
I can reproduce this quite reliably in my current setup so I'll try look into it maybe at the weekends for a minimal setup. |
I have also seen this happen, e.g.,
Here the problem is that I have deleted the blank line after |
@nnicandro Hmm, beware that mine might be a different issue. My issue have
strong connection with undoing and `org-element--cache`.
@NightMachinery
Have you ever seen the warning messages from `org-element--cache`?
|
@ed9w2in6 You’re right, the issue I raised is distinct from yours, but perhaps the solution I proposed would work for your case, as well? |
@NightMachinery In Org, src blocks can also be the results of execution of some other source block, e.g.
Running the above yields
Org is the one that is removing the source block with the |
@nnicandro I think this problem is severe enough that it warrants forking This org feature of inserting a source block as a result of another thing is not that useful (I would personally use We can of course check |
Just to confirm that I can reliably reproduce this. Evaluate buffer with error. An example is:
Which errors with: #+RESULTS:
:RESULTS:
: /tmp/ipykernel_521850/3839449454.py:12: FutureWarning: In the future `np.object` will be defined as the corresponding NumPy scalar.
: dims = np.array(['aa','ab']).astype(np.object)
# [goto error]
#+begin_example
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 12
5 # foo = xr.Dataset({'foo': xr.DataArray(data=[100,200], dims=['dim'], coords={'dim':['a','b']})})
6 # bar = xr.Dataset({'bar': xr.DataArray(data=[200,300], dims=['dim'], coords={'dim':['b','c']})})
7 # baz = xr.Dataset({'baz': xr.DataArray(data=[200,100], dims=['dim'], coords={'dim':['b','a']})})
8 # print((foo['foo']-bar['bar']).values)
9 # print((foo['foo'] - baz['baz']).values)
11 times = pd.date_range(start='2000-01-01',freq='1D',periods=3)
---> 12 dims = np.array(['aa','ab']).astype(np.object)
14 foo = xr.Dataset({'foo': xr.DataArray(data=[[1,2],[3,4],[5,6]], dims=['time','dim'], coords={'time':times, 'dim':dims})})
15 bar = xr.Dataset({'bar': xr.DataArray(data=[[2,1],[4,3],[6,5]], dims=['time','dim'], coords={'time':times, 'dim':dims[::-1]})})
File ~/local/mambaforge/envs/ds/lib/python3.10/site-packages/numpy/__init__.py:305, in __getattr__(attr)
300 warnings.warn(
301 f"In the future `np.{attr}` will be defined as the "
302 "corresponding NumPy scalar.", FutureWarning, stacklevel=2)
304 if attr in __former_attrs__:
--> 305 raise AttributeError(__former_attrs__[attr])
307 # Importing Tester requires importing all of UnitTest which is not a
308 # cheap import Since it is mainly used in test suits, we lazy import it
309 # here to save on the order of 10 ms of import time for most users
310 #
311 # The previous way Tester was imported also had a side effect of adding
312 # the full `numpy.testing` namespace
313 if attr == 'testing':
AttributeError: module 'numpy' has no attribute 'object'.
`np.object` was a deprecated alias for the builtin `object`. To avoid this error in existing code, use `object` by itself. Doing this will not modify any behavior and is safe.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
#+end_example
:END: Note that there is both an However, if I then type I can reliably recreate this bug with my (large) config. I cannot create an MWE. |
@mankoff The symptoms that you just described are exactly the same as mine. @nnicandro Do you prefer me and @mankoff to open another issue? At least the symptoms are different, if it turns out to be the same cause we can just close one of them. |
@ed9w2in6 I'm running latest org from git and updated yesterday. I cannot recreate this bug today. The git log has a lot of entries on
|
Nevermind, Still here :(. |
I posted about this issue on the Org list in case it is related to Their suggestion:
|
Yes, I get the same cache warning. I see Toggle...Warning (org-element-cache): org-element--cache: Unregistered buffer modifications detected (57640 != 55418). Resetting. If this warning appears regularly, please report the warning text to Org mode mailing list (M-x org-submit-bug-report). The buffer is: misc.org Current command: nil Backtrace: " backtrace-to-string(nil) org-element--cache-sync(# 37660) org-element-at-point() (progn (org-element-at-point)) (unwind-protect (progn (org-element-at-point)) (set-match-data save-match-data-internal 'evaporate)) (let ((save-match-data-internal (match-data))) (unwind-protect (progn (org-element-at-point)) (set-match-data save-match-data-internal 'evaporate))) (let ((element (let ((save-match-data-internal (match-data))) (unwind-protect (progn (org-element-at-point)) (set-match-data save-match-data-internal 'evaporate))))) (and (eq (org-element-type element) 'src-block) (>= (line-beginning-position) (let* ((parray (and t (let* ... ...)))) (if parray (let* ((val ...)) (if (eq val ...) 'nil (let ... val))) (let* ((val ...)) (cond (... ...) (... ...) (t ...)))))) (<= (line-end-position) (save-excursion (save-restriction (widen) (goto-char (let* (...) (if parray ... ...))) (skip-chars-backward \" \\11\\n\") (line-end-position)))) (org-element--property :language element nil nil))) org-eldoc-get-src-lang() (let ((lang (org-eldoc-get-src-lang))) (cond ((string= lang \"org\") nil) ((or (string= lang \"emacs-lisp\") (string= lang \"elisp\")) (cond ((and (boundp 'eldoc-documentation-functions) (fboundp 'elisp-eldoc-var-docstring) (fboundp 'elisp-eldoc-funcall)) (let ((eldoc-documentation-functions ...)) (eldoc-print-current-symbol-info))) ((fboundp 'elisp-eldoc-documentation-function) (elisp-eldoc-documentation-function)) (t (let (eldoc-documentation-function) (eldoc-print-current-symbol-info))))) ((or (string= lang \"c\") (string= lang \"C\")) (if (require 'c-eldoc nil t) (progn (c-eldoc-print-current-symbol-info)))) ((string= lang \"css\") (if (require 'css-eldoc nil t) (progn (css-eldoc-function)))) ((string= lang \"php\") (if (require 'php-eldoc nil t) (progn (php-eldoc-function)))) ((or (string= lang \"go\") (string= lang \"golang\")) (if (require 'go-eldoc nil t) (progn (go-eldoc--documentation-function)))) (t (let ((doc-fun (org-eldoc-get-mode-local-documentation-function lang)) (callback (car args))) (if (functionp doc-fun) (progn (if (functionp callback) (funcall doc-fun callback) (funcall doc-fun)))))))) (or (org-eldoc-get-breadcrumb) (org-eldoc-get-src-header) (let ((lang (org-eldoc-get-src-lang))) (cond ((string= lang \"org\") nil) ((or (string= lang \"emacs-lisp\") (string= lang \"elisp\")) (cond ((and (boundp ...) (fboundp ...) (fboundp ...)) (let (...) (eldoc-print-current-symbol-info))) ((fboundp 'elisp-eldoc-documentation-function) (elisp-eldoc-documentation-function)) (t (let (eldoc-documentation-function) (eldoc-print-current-symbol-info))))) ((or (string= lang \"c\") (string= lang \"C\")) (if (require 'c-eldoc nil t) (progn (c-eldoc-print-current-symbol-info)))) ((string= lang \"css\") (if (require 'css-eldoc nil t) (progn (css-eldoc-function)))) ((string= lang \"php\") (if (require 'php-eldoc nil t) (progn (php-eldoc-function)))) ((or (string= lang \"go\") (string= lang \"golang\")) (if (require 'go-eldoc nil t) (progn (go-eldoc--documentation-function)))) (t (let ((doc-fun (org-eldoc-get-mode-local-documentation-function lang)) (callback (car args))) (if (functionp doc-fun) (progn (if ... ... ...)))))))) org-eldoc-documentation-function(#f(compiled-function (string &rest plist) #)) run-hook-with-args-until-success(org-eldoc-documentation-function #f(compiled-function (string &rest plist) #)) eldoc-documentation-default() eldoc--invoke-strategy(nil) eldoc-print-current-symbol-info() #f(compiled-function () #)() apply(#f(compiled-function () #) nil) timer-event-handler([t 0 0 500000 nil #f(compiled-function () #) nil idle 0 nil]) " Disable showing Disable logging |
It is useful in some scenarios. But can be disabled, if you wish to (:results none). If you find something missing, feel free to write a feature request. |
Hi @yantar92 - thanks for following up here. It does appear that we may be discussing two different problems in this GitHub issue. The error in the latter (more recent above here) comments and that I reported on the Org mailing list is not about code generating a source block. It happens with 'normal' See comment here: #486 (comment) |
I am unable to reproduce with my config. |
I was unable to reproduce with my config yesterday either :). But I was today. Same config! :(. |
I am seeing the following in ob-jupyter: ;; KLUDGE: Remove the file result-parameter so that
;; `org-babel-insert-result' doesn't attempt to handle it while
;; async results are pending. Do the same in the synchronous
;; case, but not if link or graphics are also result-parameters,
;; only in Org >= 9.2, since those in combination with file mean
;; to interpret the result as a file link, a useful meaning that
;; doesn't interfere with Jupyter style result insertion. Do note that async evaluation API is in place in the latest Org mode. There is no need to write custom async code that might indeed be prone to various errors. Check out |
A package with similar (same?) issue: nobiot/org-transclusion#105 I believe our issue here can be similar to them, in which the culprit is usage in Lines 563 to 568 in 3a31920
usage in Lines 748 to 755 in 3a31920
A quick search in org-mode mailing list reveals a few similar issues: https://list.orgmode.org/?q=inhibit-modification-hooks I am not sure about a right fix, maybe just doing a Reading the long mailing lists for a bit, |
Why do you need to set |
Similar problem I met. I am using
the results block looks
Note that without If I change |
For anyone here experiencing the |
One thing I have just noticed is about the output which if it is several lines it is formatted in an example block. If a |
To follow up on this, I think that the results from the Python interpreter are not sanitized properly. Does anybody else still have experience where the execution of one block that generates warnings/error messages erases the contents of the notebook? EDIT: Important to mention that I have the async facility and I edit the buffer while waiting for the block to finish. |
In some scenarios (does not happen often) the executing a src block erases the appended commend of the org-mode file. The result is that everything at least until the next src block gets erased.
My guess is that in the #+RESULTS: section the :RESULTS: are not properly wrapped with the :END: block. Thus, re-executing the src block erases everything up until the next :END: block. If lucky and executed the next block it will stop in :END: of that block. If not, most likely it will erase everything. Usually this can be reverted, if I realize described behavior with an undo.
But this can lead to some nasty situations. Is there a way to introduce a fail-safe for this?
The text was updated successfully, but these errors were encountered: