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
CSS rules not always applied in the same order #69
Comments
After some digging I can confirm that my suspicions where founded. Here's self contained way to reproduce the problem:
Regardless of the threading mode, some times the result will be this:
Some other times it will be this:
Now I suspect that at some point the parser rely on the order of the keys set in a dictionary (which is completely arbitrary) to set the order of the CSS rules. I'm digging through the source code to find the exact place where the problem occurs, but I'm short on time because I have tight deadlines to respect .. I'll post updates if I find more. |
Not sure if I'm on to something or this is just an oddity, but I found something weird .. In the example above, However if you
The odd thing is .. that it always print the rules in the right order. |
Last update for today .. Dismiss my last comment, it seems this is due to a quick in the way IPython prints method output. That said I think I managed to narrow down where the problem is. In
Now if I replace At this point I'm out of idea. I don't have the time to wrap my head around the parser to understand everything that's going on so I might just give up right now and hope my investigation can set somebody on the right track. |
I would think this is caused by Python 2 ordering by object reference when no other order is specified. Example:
Creating explicit sorting should fix it. |
Closing this for now, but it's in favour of the more universal solution proposed in #299. |
Usually in CSS if you have the following code:
The border of #content should always be red since styles declared last always override previously declared styles.
However this is not the case with xhtml2pdf, with a css declaration like this sometimes the border will be blue, sometimes it will be red.
Since it's an on & off problem, it looks awfully like a threading problem. You can F5 many times and the styles will flips randomly and not necessarily every times.
I know reportlab isn't thread safe so I was pretty sure it was a threading problem, but it doesn't seems so. I tried with the dev server with --nothreading and with apache+wsgi on a single thread and the problem persist in both cases.
I dumped what the CSS parser was seeing and the CSS code was always right, which leaves us only with one possibility. The CSS rules aren't always applied in the same order.
The text was updated successfully, but these errors were encountered: