internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: web2py/web2py

Issue:
Correction of #1043 which breaks comments
#1043 introduce a specific case of HTML for some field types when in readlonly mode, but it loses comments and give inconsistency when forms contains strings and A elements (some have comments and other have not).

The problem is only a styling issue and not a HTML one. 

It was solved later in 864dbe73f251110ea690978d73d510beaeb31364 by adding a `readonly` class to labels which allow for properly vertical align with CSS.

I propose to revert 353db90a64433d384aa27d1f2043536d6d8f76ce.
Tested locally and vertical alignment between field and label is ok, and the help text is preserved among all fields.

I can make a PR if needed.



Discussion:

Resolving patch:
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -938,8 +938,6 @@ def _inner(form, fields):
             elif isinstance(controls, UL):
                 for e in controls.elements("input"):
                     e.add_class('form-control')
-            elif controls is None or isinstance(controls, basestring):
-                _controls = P(controls, _class="form-control-static %s" % col_class)
             if isinstance(label, LABEL):
                 label['_class'] = add_class(label.get('_class'),'control-label %s' % label_col_class)
 


Test patch:
Repository: web2py/web2py

Issue:
Cas broken
Reference
https://groups.google.com/forum/#!topic/web2py/yBxRYoQH9kQ

It seems that the security fix that involve Auth(.., host_names=...)  broke cas_login



Discussion:

Resolving patch:
diff --git a/gluon/tools.py b/gluon/tools.py
--- a/gluon/tools.py
+++ b/gluon/tools.py
@@ -1735,6 +1735,7 @@ def select_host(self, host, host_names=None):
             host = host_names[0]
         else:
             host = 'localhost'
+        return host
 
     def __init__(self, environment=None, db=None, mailer=True,
                  hmac_key=None, controller='default', function='user',


Test patch:
Repository: web2py/web2py

Issue:
[Feature Request] Pass onvalidation dict to smartgrid
As per [this thread](https://groups.google.com/forum/#!topic/web2py/WG28up_5YCs) on the forums, a smartgrid can be passed a limited set of params as dict to be passed to child grids. However, onvalidation isn't part of the params that can be passed to child grids via a dict. 

This is problematic because then it means a child grid created cannot have any custom validation done, for instance, to enforce multi-column unique constraints. 

I humbly request that onvalidation be part of the smartgrid params that can be passed to child tables via a dict.



Discussion:
Can you submit a patch for this? I will take it.


Resolving patch:
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -3043,7 +3043,16 @@ def format(table, row):
             query = query & constraints[table._tablename]
         if isinstance(links, dict):
             links = links.get(table._tablename, [])
-        for key in 'columns,orderby,searchable,sortable,paginate,deletable,editable,details,selectable,create,fields'.split(','):
+        for key in ('fields', 'field_id', 'left', 'headers', 'orderby', 'groupby', 'searchable', 
+                    'sortable', 'paginate', 'deletable', 'editable', 'details', 'selectable',
+                    'create', 'csv', 'links', 'links_in_grid', 'upload', 'maxtextlengths',
+                    'maxtextlength', 'onvalidation', 'onfailure', 'oncreate', 'onupdate',
+                    'ondelete', 'sorter_icons', 'ui', 'showbuttontext', '_class', 'formname',
+                    'search_widget', 'advanced_search', 'ignore_rw', 'formstyle', 'exportclasses',
+                    'formargs', 'createargs', 'editargs', 'viewargs', 'selectable_submit_button',
+                    'buttons_placement', 'links_placement', 'noconfirm', 'cache_count', 'client_side_delete',
+                    'ignore_common_filters', 'auto_pagination', 'use_cursor'
+                   ):
             if isinstance(kwargs.get(key, None), dict):
                 if table._tablename in kwargs[key]:
                     kwargs[key] = kwargs[key][table._tablename]


Test patch:
Repository: web2py/web2py

Issue:
Bug Report: Typo in tools.py
https://github.com/web2py/web2py/blob/master/gluon/tools.py#L4515

is_ctive should be is_active.  Preventing scheduler tasks from running correctly.



Discussion:
To be fair it prevents that operation to be succesful in any environment...


Resolving patch:
diff --git a/gluon/tools.py b/gluon/tools.py
--- a/gluon/tools.py
+++ b/gluon/tools.py
@@ -4512,7 +4512,7 @@ def add_permission(self,
                           ignore_common_filters=True).select(
             limitby=(0, 1), orderby_on_limitby=False).first()
         if record:
-            if hasattr(record, 'is_active') and not record.is_ctive:
+            if hasattr(record, 'is_active') and not record.is_active:
                 record.update_record(is_active=True)
             id = record.id
         else:


Test patch:
diff --git a/gluon/tests/test_tools.py b/gluon/tests/test_tools.py
--- a/gluon/tests/test_tools.py
+++ b/gluon/tests/test_tools.py
@@ -176,6 +176,19 @@ def test_attachment(self):
         attachment = parsed_msg.get_payload(1).get_payload(decode=True)
         with open(module_file, 'rb') as mf:
             self.assertEqual(attachment.decode('utf-8'), mf.read().decode('utf-8'))
+        # Test missing attachment name error
+        stream = open(module_file)
+        self.assertRaises(Exception, lambda *args, **kwargs: Mail.Attachment(*args, **kwargs), stream)
+        stream.close()
+        # Test you can define content-id and content type
+        self.assertTrue(mail.send(to=['somebody@example.com'],
+                                  subject='hello',
+                                  message='world',
+                                  attachments=Mail.Attachment(module_file, content_id='trololo', content_type='tra/lala')))
+        message = TestMail.DummySMTP.inbox.pop()
+        self.assertTrue('Content-Type: tra/lala' in message.payload)
+        self.assertTrue('Content-Id: <trololo>' in message.payload)
+
 
 # class TestRecaptcha(unittest.TestCase):
 #     def test_Recaptcha(self):
diff --git a/gluon/tests/test_validators.py b/gluon/tests/test_validators.py
--- a/gluon/tests/test_validators.py
+++ b/gluon/tests/test_validators.py
@@ -230,6 +230,8 @@ def test_IS_IN_DB(self):
         self.assertEqual(rtn, ( ('%d,%d' % (george_id, costanza_id)).split(','), 'oops'))
         rtn = IS_IN_DB(db, db.person.id, '%(name)s', error_message='oops').options(zero=False)
         self.assertEqual(sorted(rtn), [('%d' % george_id, 'george'), ('%d' % costanza_id, 'costanza')])
+        rtn = IS_IN_DB(db, db.person.id, db.person.name, error_message='oops', sort=True).options(zero=True)
+        self.assertEqual(rtn, [('', ''), ('%d' % costanza_id, 'costanza'), ('%d' % george_id, 'george')])
         db.person.drop()
 
     def test_IS_NOT_IN_DB(self):
Repository: web2py/web2py

Issue:
empty strings stored as NULL in db
https://groups.google.com/forum/#!topic/web2py/IYzhhd3eKXQ



Discussion:
Yep this is a big problem. For instance if you use appadmin to put an empty string in a users register_key it won't work. So it breaks appadmin too.


Resolving patch:
diff --git a/gluon/dal.py b/gluon/dal.py
--- a/gluon/dal.py
+++ b/gluon/dal.py
@@ -74,12 +74,12 @@ def _default_validators(db, field):
         return requires
     # does not get here for reference and list:reference
     if field.unique:
-        requires.insert(0,validators.IS_NOT_IN_DB(db, field))
-    excluded_fields = ['string','upload','text','password','boolean']
+        requires.insert(0, validators.IS_NOT_IN_DB(db, field))
+    excluded_fields = ['string', 'upload', 'text', 'password', 'boolean']
     if (field.notnull or field.unique) and not field_type in excluded_fields:
-        requires.insert(0,validators.IS_NOT_EMPTY())
+        requires.insert(0, validators.IS_NOT_EMPTY())
     elif not field.notnull and not field.unique and requires:
-        requires[0] = validators.IS_EMPTY_OR(requires[0])
+        requires[0] = validators.IS_EMPTY_OR(requires[0], null='' if field in ('string', 'text', 'password') else None)
     return requires
 
 from gluon.serializers import custom_json, xml
@@ -93,7 +93,7 @@ def _default_validators(db, field):
 DAL.representers = {
     'rows_render': sqlhtml.represent,
     'rows_xml': sqlhtml.SQLTABLE
-    }
+}
 DAL.Field = Field
 DAL.Table = Table
 


Test patch:
Repository: web2py/web2py

Issue:
RedisCache fails to delete cached objects when f=None
For background, see https://groups.google.com/d/msg/web2py/1LoXXrPlIGE/bX2u3CJ2BQAJ.

According to the book, calling `cache.model(key, f=None)` should cause `key` to be deleted from the cache. However, in `gluon.contrib.redis_cache.RedisClient.__call__`, setting `f=None` only deletes the cached object if it has expired.

This causes a problem with `@cache.action` because it relies on the `f=None` deletion method to delete pages that were cached with an invalid HTTP status.

We should change the behavior of the Redis cache to match that of the other cache models (i.e., setting `f=None` should _always_ delete the key from the cache).

Also, for extra safety, perhaps `@cache.action` should delete pages with an invalid status via `cache_model.clear(r'^%s$' % cache_key)` rather than `cache_model(cache_key, None)`.



Discussion:

Resolving patch:
diff --git a/gluon/contrib/redis_cache.py b/gluon/contrib/redis_cache.py
--- a/gluon/contrib/redis_cache.py
+++ b/gluon/contrib/redis_cache.py
@@ -85,7 +85,7 @@ def RedisCache(redis_conn=None, debug=False, with_lock=False, fail_gracefully=Fa
     try:
         instance_name = 'redis_instance_' + current.request.application
         if not hasattr(RedisCache, instance_name):
-            setattr(RedisCache, instance_name, 
+            setattr(RedisCache, instance_name,
                     RedisClient(redis_conn=redis_conn, debug=debug,
                                 with_lock=with_lock, fail_gracefully=fail_gracefully))
         return getattr(RedisCache, instance_name)
@@ -137,6 +137,10 @@ def __call__(self, key, f, time_expire=300, with_lock=None):
         value = None
         ttl = 0
         try:
+            if f is None:
+                # delete and never look back
+                self.r_server.delete(newKey)
+                return None
             # is there a value
             obj = self.r_server.get(newKey)
             # what's its ttl
@@ -149,9 +153,6 @@ def __call__(self, key, f, time_expire=300, with_lock=None):
                 if self.debug:
                     self.r_server.incr('web2py_cache_statistics:hit_total')
                 value = pickle.loads(obj)
-            elif f is None:
-                # delete and never look back
-                self.r_server.delete(newKey)
             else:
                 # naive distributed locking
                 if with_lock:


Test patch:
Repository: web2py/web2py

Issue:
ldap_auth error
1) problem
2016-06-08 10:14:17.120 WARNING ~/web2py/gluon/contrib/login_methods/ldap_auth.py do_manage_groups:582 [username] Groups are not managed successfully!
2016-06-08 10:14:17.120 DEBUG ~/web2py/gluon/contrib/login_methods/ldap_auth.py do_manage_groups:584 Traceback (most recent call last):
  File "~/web2py/gluon/contrib/login_methods/ldap_auth.py", line 535, in do_manage_groups
    db_can_join = db.can_join() if hasattr(db, 'can_join') else True
  File "~/web2py/gluon/packages/dal/pydal/base.py", line 878, in can_join
    return self._adapter.can_join()
2) solve

``` diff
diff --git a/gluon/contrib/login_methods/ldap_auth.py b/gluon/contrib/login_methods/ldap_auth.py
index c724d66..490b6d0 100644
--- a/gluon/contrib/login_methods/ldap_auth.py
+++ b/gluon/contrib/login_methods/ldap_auth.py
@@ -532,7 +532,7 @@ def ldap_auth(server='ldap',
                     'There is no username or email for %s!' % username)
                 raise
             # if old pydal version, assume this is a relational database which can do joins
-            db_can_join = db.can_join() if hasattr(db, 'can_join') else True
+            db_can_join = db.can_join() if hasattr(db._adapter, 'can_join') else True
             if db_can_join:
                 db_group_search = \
                     db((db.auth_membership.user_id == db_user_id) &
```



Discussion:

Resolving patch:
diff --git a/gluon/contrib/login_methods/ldap_auth.py b/gluon/contrib/login_methods/ldap_auth.py
--- a/gluon/contrib/login_methods/ldap_auth.py
+++ b/gluon/contrib/login_methods/ldap_auth.py
@@ -532,7 +532,7 @@ def do_manage_groups(username, password=None, group_mapping={}, db=db):
                     'There is no username or email for %s!' % username)
                 raise
             # if old pydal version, assume this is a relational database which can do joins
-            db_can_join = db.can_join() if hasattr(db, 'can_join') else True
+            db_can_join = db.can_join() if hasattr(db._adapter, 'can_join') else True
             if db_can_join:
                 db_group_search = \
                     db((db.auth_membership.user_id == db_user_id) &


Test patch:
Repository: web2py/web2py

Issue:
gluon/scheduler.py - "format"  in  "db.define_table('scheduler_task',..."
please replace this line "format='%(task_name)s')"
with this line "format='(%(id)s) %(task_name)s')"



Discussion:
what's the pressing reason behind this request ?

I just think it is more easy (for me at least) to manage the scheduler using appadmin and/or custom SQLFORM.grid() views.

okay, nothing major then. I'll fix before the next scheduler release which introduces a juicy new feature. Feel free to ping again in two weeks if you don't see it fixed in trunk.


Resolving patch:
diff --git a/gluon/scheduler.py b/gluon/scheduler.py
--- a/gluon/scheduler.py
+++ b/gluon/scheduler.py
@@ -833,7 +833,7 @@ def define_tables(self, db, migrate):
             Field('assigned_worker_name', default='', writable=False),
             on_define=self.set_requirements,
             migrate=self.__get_migrate('scheduler_task', migrate),
-            format='%(task_name)s')
+            format='(%(id)s) %(task_name)s')
 
         db.define_table(
             'scheduler_run',


Test patch:
Repository: web2py/web2py

Issue:
web2py returns 400 bad request when issuing an HTTP PATCH request
I am trying to run an action using HTTP PATCH request, but instead of executing the controller function, web2py simply returns HTTP error 400.

P.S. Everywhere that I read about web2py, I find only HTTP GET, POST, PUT and DELETE methods only. Are other methods even supported by web2py? If they are not enabled by default, is there any configuration to enable them?



Discussion:
Are you trying this with the default rocket webserver?
Or do you have web2py configured with Apache / Nginx / similar webservers?

Based on the code that I see for the rocket webserver, I see that it doesn't have 'PATCH' as a request method. See line: https://github.com/web2py/web2py/blob/327c40cd1721025653504d8f49a8dd592a0e8438/gluon/rocket.py#L1205
Not sure if this is 'working as designed' or needs to be addressed.

If you are using any other webserver, I think the webserver provides configuration options to allow the methods you require.
You may also find this discussion to provide a little more context on web2py supported HTTP methods: https://groups.google.com/forum/#!searchin/web2py/patch$20head/web2py/IqJxYLR6b1g/LwrfF-rkEdQJ

I was trying it with the default webserver.
I'll try it with apache and let you know if it works.

I tried it with apache web server and it works fine.


Resolving patch:
diff --git a/gluon/rocket.py b/gluon/rocket.py
--- a/gluon/rocket.py
+++ b/gluon/rocket.py
@@ -1184,17 +1184,17 @@ class SSLError(socket.error):
 # Define Constants
 re_SLASH = re.compile('%2F', re.IGNORECASE)
 re_REQUEST_LINE = re.compile(r"""^
-(?P<method>OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT)   # Request Method
-\                                                            # (single space)
+(?P<method>OPTIONS|GET|HEAD|POST|PUT|DELETE|PATCH|TRACE|CONNECT) # Req Method
+\                                                                # single space
 (
-    (?P<scheme>[^:/]+)                                       # Scheme
+    (?P<scheme>[^:/]+)                                           # Scheme
     (://)  #
-    (?P<host>[^/]+)                                          # Host
+    (?P<host>[^/]+)                                              # Host
 )? #
-(?P<path>(\*|/[^ \?]*))                                      # Path
-(\? (?P<query_string>[^ ]*))?                                # Query String
-\                                                            # (single space)
-(?P<protocol>HTTPS?/1\.[01])                                 # Protocol
+(?P<path>(\*|/[^ \?]*))                                          # Path
+(\? (?P<query_string>[^ ]*))?                                    # Query String
+\                                                                # single space
+(?P<protocol>HTTPS?/1\.[01])                                     # Protocol
 $
 """, re.X)
 LOG_LINE = '%(client_ip)s - "%(request_line)s" - %(status)s %(size)s'


Test patch:
Repository: web2py/web2py

Issue:
XML helper and incorrect HTML
XML crashes while trying to sanitize some sorts of incorrect html.

For example:

```
a = '</em></em>' # wrong html
b = XML(a, sanitize=True)
```

Result:
`<type 'exceptions.IndexError'> pop from empty list`



Discussion:
Well that _is_ invalid XML...


Resolving patch:
diff --git a/gluon/sanitizer.py b/gluon/sanitizer.py
--- a/gluon/sanitizer.py
+++ b/gluon/sanitizer.py
@@ -129,7 +129,7 @@ def handle_starttag(
 
     def handle_endtag(self, tag):
         bracketed = '</%s>' % tag
-        self.in_disallowed.pop()
+        self.in_disallowed and self.in_disallowed.pop()
         if tag not in self.permitted_tags:
             if (not self.strip_disallowed):
                 self.result += xssescape(bracketed)


Test patch:
Repository: web2py/web2py

Issue:
Disabling sessions via routes.py is broken
Here is the original commit allowing sessions to be disabled via routes.py: https://github.com/web2py/web2py/commit/cbcac3af70251b2ba8274e4f63f08a02dbf276fc#diff-f765c19a6807e5043a9be59d19880938R525

In main.py, that commit added three instances of `if not env.web2py_disable_session:` to conditionally run the session connecting and saving logic. However, at some point, the latter two instances of the `if` statement were removed, which causes an error when sessions have been disabled. It is not clear why those lines were removed, but they should either be restored or some alternative mechanism should be put in place to allow the disabling of sessions.



Discussion:

Resolving patch:
diff --git a/gluon/main.py b/gluon/main.py
--- a/gluon/main.py
+++ b/gluon/main.py
@@ -454,7 +454,8 @@ def wsgibase(environ, responder):
                     # ##################################################
                     # on success, try store session in database
                     # ##################################################
-                    session._try_store_in_db(request, response)
+                    if not env.web2py_disable_session:
+                        session._try_store_in_db(request, response)
 
                     # ##################################################
                     # on success, commit database
@@ -471,8 +472,8 @@ def wsgibase(environ, responder):
                     # if session not in db try store session on filesystem
                     # this must be done after trying to commit database!
                     # ##################################################
-
-                    session._try_store_in_cookie_or_file(request, response)
+                    if not env.web2py_disable_session:
+                        session._try_store_in_cookie_or_file(request, response)
 
                     # Set header so client can distinguish component requests.
                     if request.cid:


Test patch:
Repository: web2py/web2py

Issue:
bug in paths
solve:

``` diff
git diff gluon/admin.py
diff --git a/gluon/admin.py b/gluon/admin.py
index 3eb3bc5..e0372ba 100644
--- a/gluon/admin.py
+++ b/gluon/admin.py
@@ -449,7 +449,7 @@ def create_missing_folders():
     """
     paths = (global_settings.gluon_parent, abspath(
         'site-packages', gluon=True), '')
-    [add_path_first(path) for p in paths]
+    [add_path_first(path) for path in paths]


 def create_missing_app_folders(request):

```



Discussion:

Resolving patch:
diff --git a/gluon/admin.py b/gluon/admin.py
--- a/gluon/admin.py
+++ b/gluon/admin.py
@@ -449,7 +449,7 @@ def create_missing_folders():
     """
     paths = (global_settings.gluon_parent, abspath(
         'site-packages', gluon=True), '')
-    [add_path_first(path) for p in paths]
+    [add_path_first(p) for p in paths]
 
 
 def create_missing_app_folders(request):


Test patch:
Repository: web2py/web2py

Issue:
to_unicode not imported
This module calls to_unicode() from the gluon._compat module in line 3500, but to_unicode() is not imported. it should be included in line 22.

`
from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, unicodeT, to_native, to_unicode
`



Discussion:

Resolving patch:
diff --git a/gluon/html.py b/gluon/html.py
--- a/gluon/html.py
+++ b/gluon/html.py
@@ -20,7 +20,7 @@
 import base64
 from gluon import sanitizer, decoder
 import itertools
-from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT, urllib_quote, to_bytes, to_native, to_unicode, basestring, urlencode, implements_bool
+from gluon._compat import reduce, pickle, copyreg, HTMLParser, name2codepoint, iteritems, unichr, unicodeT, urllib_quote, to_bytes, to_native, to_unicode, basestring, urlencode, implements_bool, text_type
 from gluon.utils import local_html_escape
 import marshal
 
@@ -122,7 +122,7 @@ def xmlescape(data, quote=True):
     if hasattr(data, 'xml') and callable(data.xml):
         return to_bytes(data.xml())
 
-    if not(isinstance(data, basestring)):
+    if not(isinstance(data, (text_type, bytes))):
         # i.e., integers
         data=str(data)
     data = to_bytes(data, 'utf8', 'xmlcharrefreplace')
@@ -1040,7 +1040,7 @@ def elements(self, *args, **kargs):
         hello
         >>> a.elements('a[u:v=$]')[0].xml()
         '<a id="1-1" u:v="$">hello</a>'
-        >>> a=FORM( INPUT(_type='text'), SELECT(range(1)), TEXTAREA() )
+        >>> a=FORM( INPUT(_type='text'), SELECT(list(range(1))), TEXTAREA() )
         >>> for c in a.elements('input, select, textarea'): c['_disabled'] = 'disabled'
         >>> a.xml()
         '<form action="#" enctype="multipart/form-data" method="post"><input disabled="disabled" type="text" /><select disabled="disabled"><option value="0">0</option></select><textarea cols="40" disabled="disabled" rows="10"></textarea></form>'
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -19,7 +19,7 @@
 import re
 
 import os
-from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, unicodeT, to_native
+from gluon._compat import StringIO, unichr, urllib_quote, iteritems, basestring, long, unicodeT, to_native, to_unicode
 from gluon.http import HTTP, redirect
 from gluon.html import XmlComponent, truncate_string
 from gluon.html import XML, SPAN, TAG, A, DIV, CAT, UL, LI, TEXTAREA, BR, IMG


Test patch:
diff --git a/gluon/tests/test_html.py b/gluon/tests/test_html.py
--- a/gluon/tests/test_html.py
+++ b/gluon/tests/test_html.py
@@ -253,6 +253,7 @@ def test_DIV(self):
 
         # test .get('attrib')
         self.assertEqual(DIV('<p>Test</p>', _class="class_test").get('_class'), 'class_test')
+        self.assertEqual(DIV(b'a').xml(), b'<div>a</div>')
 
     def test_CAT(self):
         # Empty CAT()