warnings module saves all warning messages permanently ?!

Issue #1822 resolved
Mike Bayer repo owner created an issue

need to confirm this is the case, and then need to remove all string interpolations from warnings, i.e. _warn_on_bytestring. We then need to prepare for all the user requests to put it back in.

Comments (7)

  1. Former user Account Deleted

    Hi!

    It was me, who posted that message in googlegroups. What questions do I need to answer? =)

    Here's a simple test:

    nekto@nekto-laptop:~$ cat /tmp/test_warnings.py 
    import warnings
    
    warnings.simplefilter("ignore")
    print "Registry is: %s" % globals().get("__warningregistry__")
    
    for _ in xrange(10000):
        warnings.warn("1")
    
    print "Registy lenght is %d" % len(globals()["__warningregistry__"]("__warningregistry__"))
    
    for i in xrange(10000):
        warnings.warn(str(i))
    
    print "Registy lenght is %d" % len(globals()["__warningregistry__"]("__warningregistry__"))
    nekto@nekto-laptop:~$ python /tmp/test_warnings.py 
    Registry is: None
    Registy lenght is 1
    Registy lenght is 10001
    

    Please add nikita.vetoshkin@gmail.com to CC.

  2. Mike Bayer reporter

    confirmed:

        def test_unicode_warnings(self):
            metadata = MetaData(testing.db)
            table1 = Table("mytable", metadata,
                Column('col1', Integer, primary_key=True,
                                    test_needs_autoincrement=True),
                Column('col2', Unicode(30)))
    
            metadata.create_all()
    
            i = [1](1)
            @testing.emits_warning()
            @profile_memory
            def go():
                # execute with a non-unicode object.
                # a warning is emitted, this warning shouldn't
                # clog up memory.
                testing.db.execute(table1.select().where(table1.c.col2=='foo%d' % i[0](0)))
                i[0](0) += 1
            try:
                go()
            finally:
                metadata.drop_all()
    

    output:

    sample gc sizes: [45496, 45497, 45498, 45499, 45500, 45501, 45502, 45503, 45504, 45505, 45506, 45507, 45508, 45509, 45510, 45511, 45512, 45513, 45514, 45515, 45516, 45517, 45518, 45519, 45520, 45521, 45522, 45523, 45524, 45525, 45526, 45527, 45528, 45529, 45530, 45531, 45532, 45533, 45534, 45535, 45536, 45537, 45538, 45539, 45540, 45541, 45542, 45543, 45544](45495,)
    
  3. Former user Account Deleted

    Would it be possible to print the column name instead in the warning? I often find myself trying to figure out where the problem is but without knowing which column it is that can be very cumbersome if you have long queries with many columns.

  4. Mike Bayer reporter

    Replying to guest:

    Would it be possible to print the column name instead in the warning? I often find myself trying to figure out where the problem is but without knowing which column it is that can be very cumbersome if you have long queries with many columns.

    unfortunately we don't have the column name available at that point. the usual method of squashing warnings is to set the warnings filter to raise an exception, at which point you get a full stack trace.

  5. Log in to comment