-
Notifications
You must be signed in to change notification settings - Fork 861
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
3.2.1 breaks when defusedxml is loaded #950
Comments
You can checkout the diff: 3.1...3.2.1. Right now I'd be inclined to say it is an nbconvert issue, but I know nothing about that package and what it does. As far as Python Markdown is concerned it works and passes all tests. You have a unique environment issue. If you are able to track down the issue, depending on what it is, maybe it could be addressed here, but we'd need more info. |
|
A few things immediately jump out at me when looking at your test case:
|
Hi there. Let me take these by number:
So this is still a “valid” test case, as long as you only invoke
|
As
This doesn't answered my question: Does the error occur if no footnotes exist in the document? If so, what is the traceback (which obviously wouldn't come from within a call to the footnote parser). I'm guessing footnotes are a red herring here, but I can't be sure with the information provided so far.
Given the lack of information above, I have no way of knowing if this is relevant or not. |
Hello again,
1) yes, it is an instance of markdown_renderer. Please give me some credit, I am indeed trying to help. Why else would I have filed a ticket here? What more info is necessary? Why the (perceived) hostility?
2) the error does _not_ occur without footnotes (in a universe of 7000-odd documents, it only occurred in the ones with footnotes-roughly 500).
I tried many variations on footnote markup, contents, with or without inline links - the mere presence of any footnote broke 3.2.1 in this situation whereas 3.1 worked with all the versions of nbconvert I tried (admittedly only two).
3) It is the information I have, within the time I had to make it available after a long series of tests. If the info as a whole is not relevant or helpful, feel free to close the ticket - I am happy to wait until this is fixed through some other means, or try to build a fully self-contained test case that satisfies your criteria at a later date.
(Also, kindly note that going to and fro both Markdown versions and checking all the other libraries involved in multiple combinations did take a while, to the point where I ended up setting up several virtualenvs to pin this down - the imports and the snippet of code I shared were the smallest bits I could snip off to demonstrate - as an example - that it was indeed an interaction between at least two recent versions of nbconvert and Markdown 3.2.1 that was breaking things, and opening up a private repo and pointing to a set of branches would likely not have been as easy a way to demonstrate the issue...)
Thanks!
… On 29 Apr 2020, at 19:47, Waylan Limberg ***@***.***> wrote:
I had removed the imports for those by the time I reached this point, since I had already established that imports alone were enough to break render_markdown.
So this is still a “valid” test case, as long as you only invoke render_markdown (we’re splitting hairs here, but you get the gist of things).
As render_markdown only calls methods of an undefined object markdown_renderer, this is not a valid test. I have no idea if markdown_renderer is an instance of markdown.Markdown or some custom subclass (I can only assume it is one of the two based on the calls to reset().convert()). I also have no way of knowing what arguments have been used to create the Markdown instance. So, no, I am not able to replicate the test or the error.
2 the document did have footnotes, and the extension is in fact enabled. I had fiddled with the various configuration options and markup formatting to make sure of that well before I got to this point.
This doesn't answered my question: Does the error occur if no footnotes exist in the document? If so, what is the traceback (which obviously wouldn't come from within a call to the footnote parser). I'm guessing footnotes are a red herring here, but I can't be sure with the information provided so far.
I do not know what nbconvert does besides also importing markdown. All I can add is that I use lxml in the same project, and that is (naturally) not affected (I might have noticed something else in my XML processing otherwise)
Given the lack of information above, I have no way of knowing if this is relevant or not.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Sorry but I still have no idea what |
markdown_renderer = Markdown(extensions=[
"markdown.extensions.extra",
"markdown.extensions.toc",
"markdown.extensions.smarty",
"markdown.extensions.codehilite",
"markdown.extensions.meta",
"markdown.extensions.sane_lists"
], extension_configs = {
"codehilite": {
"css_class": "highlight"
}
},
output_format="html5"
) |
I can confirm I am seeing the same behavior. I also searched through I was able to trim a failing example down to this most simple form: import markdown
from defusedxml import ElementTree
src = '''
Markdown paragraph with a footnote.[^1]
[^1]: Single line footnote.
'''
markdown.markdown(src, extensions=['footnotes']) I tried other variations and nothing else seems to make a difference one way or the other. The error always occurs so long as all three of the following are true:
Change any one of those and the error no longer occurs. I am stumped as to the cause of the error. Below is the relevant portion of a
I confirmed that the I also look through the By the way, with the example document, this is the second time this line of code is called. The first time was for the paragraph in the body of the document. No error was raised there. The only different was that the |
@facelessuser @mitya57 could you take a look at this? I broke the issue down in my last comment and I am stumped. Thanks. |
I may see if I can take a look sometime soon, but I just moved, so things are a little chaotic for me right now 🙂 . |
Looks like it is related to this code: https://github.com/tiran/defusedxml/blob/v0.6.0/defusedxml/ElementTree.py#L44-L53. After that code is executed, the Element class changes its ID, so Python will consider it different to the previous version of it: >>> import sys, importlib
>>>
>>> import xml.etree.ElementTree
>>> id(xml.etree.ElementTree.Element)
9581696
>>>
>>> import xml.etree.ElementTree
>>> id(xml.etree.ElementTree.Element) # stays the same
9581696
>>>
>>> pymod = sys.modules.pop("xml.etree.ElementTree")
>>> cmod = sys.modules.pop("_elementtree")
>>>
>>> sys.modules["_elementtree"] = None
>>> pure_pymod = importlib.import_module("xml.etree.ElementTree")
>>> sys.modules["_elementtree"] = cmod
>>> sys.modules["xml.etree.ElementTree"] = pymod
>>>
>>> import xml.etree.ElementTree
>>> id(xml.etree.ElementTree.Element) # now different
25336288 |
Good catch. I looked at that code, but apparently missed what it was doing. But why does the error occur only for footnotes, but not for anywhere else? |
This is not specific to footnotes, I can reproduce it with import markdown
from defusedxml import ElementTree
src = '''
The HTML specification
is maintained by the W3C.
*[HTML]: Hyper Text Markup Language
*[W3C]: World Wide Web Consortium
'''
markdown.markdown(src, extensions=['abbr']) This happens because Moving the |
Right. Of course. I had considered that at one point, but that was before I new what was causing the problem to begin with.
I suspected that might fix it. @rcarmo the fix for this is for you to import Yes, this was not an issue in previous versions of Markdown, but that was because we were importing our own copy of the etree package. We are no longer doing that (and never should have needed to). I also understand why I am closing this as wontfix. |
I haven't tested it myself, but I suspect this will be resolved when tiran/defusedxml#40 lands. |
Supposedly, this was fixed this in tiran/defusedxml#60 and tiran/defusedxml#63. According to their changelog, those changes should be available in difusedxml 0.8.0, whenever that is released. |
I was upgrading one of my projects from
markdown==3.1
tomarkdown==3.2.1
, and had a very weird behaviour that was quite hard to track down.In my test case, I had this in my imports:
When I called only
render_markdown
, I got this pretty obscure exception:Reverting back to
markdown==3.1
"fixed" it, and it took me a long time to figure out what caused it in the first place.As it turns out, it went away when I removed the
nbconvert
import or moved it insiderender_ipynb
(which is bad form, but turned out to be the quickest workaround). I assume thatnbconvert
does some kind of conflicting initialization tomarkdown
that does not go away withreset()
...But since it wasn't happening in
markdown==3.1
and happens in both still versions ofnbconvert
I've tried (nbconvert==5.5.0
andnbconvert==5.6.1
), I'm assuming something changed inmarkdown
to cause this issue.The text was updated successfully, but these errors were encountered: