13

I have posted code in Stack Overflow questions and answers many times, but for some reason the post shown in the attached screenshot is not being accepted.

Note that the code IS correctly identified in the preview!? I've tried prepending four spaces before pasting the code, and I've tried using the editor's code widget, but nothing works.

Here's the second half of the post, as requested:

Enter image description here

And a link to the pastie with the original Markdown.

And the original Markdown code

I am noticing a behavior around postgres transactions (the query
happens to involve postgis if that matters) that has me perplexed, and
it seems a general enough question that others might be interested.

in brief, i am caching zip codes found using a `geom__contains` query.
the following view uses both the `@transaction.atomic` and
`with transaction.atomic()` context, as i understand is best practice.  note
i have some verbose timing reported because i was curious:

    @transaction.atomic
    def add_geo(request):
        begTime = datetime.now()
        begTimeStr = begTime.strftime('%y%m%d_%H%M%S')

        print 'add_geo: Start=%s' % (begTimeStr)
        nmissPt = 0
        nullPt = Point([])
        rptInterval = 10000
        for i,c in enumerate(OakCrime.objects.all()):
            try:
                with transaction.atomic():
                    # pnt X is longitude, Y is latitude
                    pnt = Point(c.long, c.lat)
                    c.point = pnt

                    if c.point==nullPt:
                        nmissPt += 1
                        continue

                    zipgeo = Zip5Geo.objects.get(geom__contains=pnt)
                    c.zip = zipgeo.zcta5ce10

            except IntegrityError,e:
                print 'add_geo Integrity?! %d %s %s' % (i,c.opd_rd,e)

            except Exception, e:
                print 'add_geo?! %d %s %s' % (i,c.opd_rd,e)

            if (i % rptInterval) == 0:
                elapTime = datetime.now() - begTime
                print 'add_geo: %d %s NMiss=%d' % (i,elapTime.total_seconds(),nmissPt)

        return HttpResponse("You're at add_geo")

This generates the following timing log:

    add_geo: Start=170330_121846
    add_geo: Start=170330_121857
    add_geo: 0 40.425168 NMiss=0
    add_geo: 0 44.995976 NMiss=0
    add_geo: 1000 59.747211 NMiss=86
    add_geo: 1000 49.271699 NMiss=86
    add_geo: 2000 63.778699 NMiss=162
    add_geo: 2000 53.246911 NMiss=162
    ...

Question#1: there is significant startup time; what's going on during
that?

Question#2: *Why are there **two** reporting lines generated* each
time?!  note that this includes the very first "Start=" message!?

Question#3: Why is the *first* elapsed time ~ 10 seconds *ahead of*
the second?!

Question#4: When i change the reporting interval to 10000, i now get
only one reporting line vs. two?  This makes me think there must be
some per-transaction buffer or similar that i am within with n=1000
but beyond at n=10000?  That seems a good thing, and the process does
seem to run much fast with n=10000; why is that?
17
  • 2
    What's below the part you posted?
    – NobodyNada
    Mar 30, 2017 at 20:18
  • 51
    You have to properly capitalize each "I". Otherwise the error won't go away. Also each sentence has to start with a capital letter.
    – honk
    Mar 30, 2017 at 20:27
  • 3
    @honk WTF?! #1: these changes have nothing to do with the "code formatting" that the error message mentions. #2: are you really saying SO has turned up formatting controls on free text to this level?! sorry, i don't mean to be angry at the messenger but if true this seems crazy.
    – rikb
    Mar 30, 2017 at 21:08
  • @NobodyNada, ok, i added a second screenshot of the last bit of the post
    – rikb
    Mar 30, 2017 at 21:12
  • 4
    I think it might be the "with transaction.atomic()" as it appears as though you've included a line break in your inline code. Hard to tell from a screenshot. Regardless, the question in the screenshot, if posted, could be closed as "too broad" as you are asking four questions in one. Mar 30, 2017 at 21:28
  • 1
    thanks @MikeMcCaughan. i removed the line break within the "with transaction.atomic()", same issue remains. and if i get the editorial "too broad" response, THAT is something i can deal with!
    – rikb
    Mar 30, 2017 at 21:33
  • 3
    It would be nice if you could post the actual markdown you have, rather than screenshots. That would help those who wish to recreate the bug. Mar 30, 2017 at 21:35
  • @MikeMcCaughan, done! pastiebin.com/58dd7b55af456 happy to help you help me!
    – rikb
    Mar 30, 2017 at 21:42
  • 2
    Please include the markdown in the question itself, not only on a third-party site. Many people don't have access to sharing sites. Mar 30, 2017 at 21:43
  • @MikeMcCaughan done#2. interesting that it renders just fine here in Meta?
    – rikb
    Mar 30, 2017 at 21:47
  • 1
    Yeah, I copied and pasted your markdown into a new question and didn't get any errors, but I think that error comes up when you click [Post your question], and I don't really want to do that, especially since I don't know what language it's in :). I'll let people who are more experienced in asking questions weigh in on this. Mar 30, 2017 at 21:53
  • 40
    @rikb: I'm sorry for trolling you, but the goal of Stack Overflow is to build a repository of high quality questions and answer. I would be great if you could properly capitalize your posts (in addition to producing good content) in order to contribute to that goal.
    – honk
    Mar 31, 2017 at 7:03
  • 2
    The question part also contains some lines that contain i surrounded by spaces, which could be taken to be a variable name. Which brings us back to yesterday's discussion about properly capitalizing the first person singular.
    – shoover
    Mar 31, 2017 at 22:22
  • 7
    Of course, the far more sensible alternative is to add a heuristic that detects lowercase i in free text and suggests capitalizing it if it's not intended to be a variable name. (Not that variable names couldn't be an uppercase i, but let's be honest, how often do you see that in practice?)
    – BoltClock
    Apr 1, 2017 at 6:46
  • 2
    @BoltClock when I use them along l's
    – Braiam
    Apr 1, 2017 at 11:12

3 Answers 3

21

I suspect that SO's question filter is misidentifying some of the non-code parts of your question as program code.

I can't tell for sure which parts, but if I had to guess, my money would be on the second paragraph, which I've taken the liberty of quoting below (as a code block, to show it as it appears in your Markdown input):

in brief, i am caching zip codes found using a `geom__contains` query.
the following view uses both the `@transaction.atomic` and 
`with transaction.atomic()` context, as i understand is best practice.  note
i have some verbose timing reported because i was curious:

This paragraph contains:

  • a lot of inline code, which might confuse the filter even though (in this case) it's properly backticked,
  • hard line breaks, which are common in code but rarely used (or useful) in normal Markdown text, and
  • no capital letters, which are typically found at least once per sentence in normal English prose, but are often absent from program code (or occur in places where they wouldn't in normal writing).

It also appears immediately before an actual indented code block, which is a common location for misformatted code. While I have no detailed knowledge of what heuristics the filter uses to detect code, I wouldn't be surprised if some combination of these things was enough to trigger it.


In any case, if you get an error message like this, there's a fairly simple way to find out which part of your post is triggering it: just try converting each paragraph of your post into a code block, one at a time, until the error goes away. (If converting any single paragraph doesn't help, try doing it for several at a time.)

Of course, the problem here is that, if and when you succeed in getting rid of the error, your question will likely get posted as it is. To avoid getting immediately downvoted due to bad formatting, you may want to proactively include a note above the paragraph you're testing, e.g. like this:

Note: The site thinks the following paragraph looks like code, and is not letting me post this question unless I format it as a code block. I'll try to edit my question to fix it, and I apologize for the poor formatting in the mean time.

Of course, once you know which part of your question is actually causing the problem, fixing it properly (and, if appropriate, submitting a more useful bug report about the misdetection) should be easier.

8
  • 1
    Ps. See also this earlier report about a similar issue, which eventually turned out to have been triggered by a missing blank line after a Markdown header. Apr 1, 2017 at 12:46
  • thanks for your thoughtful analysis @IlmariKaronen . my current conclusion is that SO has become concerned with form over content. yes, perfectly formatted text and code is desirable. but in newsgroup/blog/social media forums like this i am more relaxed than, for example, in scientific publications. i also happen to have nerve damage that makes my left little finger lazy, and am OK with letting uncapitalized I's slip by. i consider the time i've spent in this Meta discussion as overhead in communicating with the SO (django/postgres) community i was trying to meet. for now, I won't try.
    – rikb
    Apr 1, 2017 at 20:34
  • 8
    @rikb this is not a "newsgroup/blog/social meda forum" like the rest. If anything, it strives to become a professional information base for programming. It's written by experts in various fields, indexed by tags according to broader subjects, it's very strongly peer-reviewed...does that ring a bell? I'm truly sorry for your disability, but hopefully there are other ways of capitalizing your sentences. Apr 2, 2017 at 10:51
  • @AndrasDeak i appreciate high quality info as much as anyone, and that SO is STRIVING to improve theirs (as in, not there yet). and if SO wants to focus on special details related to included code, they would do much better providing a PREVIEWER that supported the style they favor. currently SO uses some opaque filter code and forces its CONTENT PRODUCERS to try to divine just what is what with experiments like those described above. consider the typos in just the comments here; should we expect those to be disallowed next?
    – rikb
    Apr 2, 2017 at 19:12
  • 1
    @rikb I think it's clear that your specific question was caught in the net by accident, cf. that the error message you got was about badly formatted code rather than sloppy style. I wish that the system actually had some filters for only allowing content through only if said content is not a visual horror show, but anybody who looks at the front page will see that this is not the case. Your contributions are obviously important to the site and the community, I just wanted to express my disagreement with your stance on the importance of proper style on Stack Overflow. Apr 2, 2017 at 19:28
  • @AndrasDeak we can agree to disagree. and i think we can agree that the missing bit is a PREVIEWER that SO could easily develop, probably in less time than we've all spent on this topic. Regards, Rik
    – rikb
    Apr 3, 2017 at 4:39
  • 1
    @rikb: What kind of a previewer are you thinking about? I assume you mean something other than the Markdown preview that we already have? Apr 3, 2017 at 11:57
  • @IlmariKaronen contributions (including mine) currently get dinged for bad formatting, without any help in localizing, then correcting the error. they need (a test suite to develop a filter) that lets posters know what/where/why their error is. and/or: SO could commit to a specific markdown format that does what they think necessary.
    – rikb
    Apr 4, 2017 at 2:41
1

I had this problem and I eventually figured out that my multiple (6+) [labeled links][some-description] were causing the error. I replaced [some-description] with [1] (2, 3 etc.) on all my links and it passed the inspection.

1
  • Same problem, but I fixed it by making my list of references (to similar SO questions that I had already researched) block quotes.
    – dav
    Apr 16, 2019 at 18:12
-5

the easiest way is go to an "online text-to-html convert website like https://wordtohtml.net/. Paste your text and code to the text/word section (left side) and copy the html from the html section (right side) and paste it to stackoverflow with all the html markups. It took me 2 seconds.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .