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

Issue:
session.renew() should delete the file/DB record
_From [mandarv..._at_gmail.com](https://code.google.com/u/108507264684706694414/) on October 17, 2014 20:10:01_

https://groups.google.com/d/msg/web2py/j-GwnDc0G6g/MZAyrmn4BVcJ As part of this discussion - Anthony asked to open an issue. What is the expected output? What do you see instead? session.renew() just "clears" the underlying Storage() object.
but the files/DB record remains.
This could lead to session hijacking security issue - since such "renewed" session can be used by attacker - and since the file/DB record remains, it is used as a "valid" session (Then what is the use of renew() ?) What version of the product are you using? On what operating system? 2.9.5 + linux
But this isn't likely OS specific Please provide any additional information below. gluon/global.py : Session.clear() should have code to delete the file/db record after the Storage.clear() is called.

_Original issue: http://code.google.com/p/web2py/issues/detail?id=1999_



Discussion:

Resolving patch:
diff --git a/gluon/globals.py b/gluon/globals.py
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -1053,6 +1053,20 @@ def save_session_id_cookie(self):
                 rcookies[response.session_id_name]['expires'] = expires
 
     def clear(self):
+        # see https://github.com/web2py/web2py/issues/735
+        response = current.response
+        if response.session_storage_type == 'file':
+            target = recfile.generate(response.session_filename)
+            try:
+                os.unlink(target)
+            except:
+                pass
+        elif response.session_storage_type == 'db':
+            table = response.session_db_table
+            if response.session_id:
+                (record_id, sep, unique_key) = response.session_id.partition(':')
+                if record_id.isdigit() and long(record_id) > 0:
+                    table._db(table.id == record_id).delete()
         Storage.clear(self)
 
     def is_new(self):


Test patch:
Repository: web2py/web2py

Issue:
2.10.1-3 / Windows / cache errors
Following the discussion here: https://groups.google.com/d/msg/web2py/Ukk5FTy17is/RQVx6sv8jkoJ
I put together a small script to recreate the "issues while using the cache"

```
$ python web2py.py -S test

>>> db = DAL('sqlite://cache_test.db', pool_size=0)
>>> db.define_table('t1', Field('name',type='string'))
>>> db.t1.insert(name='A1')
>>> cache_settings = dict(cache=(cache.disk, 30), cacheable=True)
>>> rows = db(db.t1.id > 0).select(**cache_settings)
>>> rows = db(db.t1.id > 0).select(**cache_settings)
```

The screenshot illustrates the result
![cache_test](https://cloud.githubusercontent.com/assets/11280/6957754/46739d48-d91e-11e4-90e7-f09d06de56a9.png)



Discussion:
I can't replicate this issue with the codebase after my #891 fix I would say this should be closed.

Hmm, am on the latest codebase too. My git log lists your fix too. Not sure what is going on here. 
My environment (if that helps)
- Windows 8.1 64bit / Microsoft Windows [Version 6.3.9600]
- Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32

Let me take another shot at this.

That's exactly the environment where I tested it. Is it possible that you did not restart web2py after updating?

Yes, I did. 
In any case, went ahead and downloaded the Windows binary, and the source from the http://web2py.com/init/default/download (for Normal Users)
Tried this out again on these versions, and I see the same error.
![cache_test](https://cloud.githubusercontent.com/assets/11280/6978706/b7ebc810-d9f5-11e4-9e32-9725ad187333.png)

I decided to try this on my **Ubuntu VM**. I didn't see this error in the Ubuntu VM, but a different one. Have listed this here: #899

oddly enough, the source version has no issues. On Windows with the current binaries, I see the same error.

Hmm, so it works in src, and not in bin. Weird. 
Summarizing the findings so far

| tested by | issue in src | issue in bin |
| --- | --- | --- |
| @leonelcamara | No | ? |
| @niphlod | No | Yes |
| @kirsn | Yes | Yes |

Have created a simple script to test this out. The script is here: https://gist.github.com/kirsn/27d50c2863cde0376022
Save this script as `cache_test_script.py`

Run this: `python web2py.py -S test_cache -R cache_test_script.py`

I run that script without any issue using the source version.

2.10.3 source AND binary ends with a permission denied error. current trunk behaves the in the same way.

@leonelcamara : found the error, will post a PR soon.

and if you try to run system tests on windows......... they fail. @mdipierro : will open a new PR soon, but I'd encourage appveyor on web2py too to test web2py on windows. (codecov too, since we used it on pydal)


Resolving patch:
diff --git a/gluon/cache.py b/gluon/cache.py
--- a/gluon/cache.py
+++ b/gluon/cache.py
@@ -353,7 +353,7 @@ def __getitem__(self, key):
                 raise KeyError
 
             self.wait_portalock(val_file)
-            value = pickle.load(recfile.open(key, 'rb', path=self.folder))
+            value = pickle.load(val_file)
             val_file.close()
             return value
 


Test patch:
Repository: web2py/web2py

Issue:
Typo in models/db.py for mail server
Hi, 

I found a small typo, which prohibits sending mails in models/db.py line 65:
mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.sender')

should be (smtp.server instead of smtp.sender):
mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.server') 

thanks



Discussion:

Resolving patch:
diff --git a/applications/welcome/models/db.py b/applications/welcome/models/db.py
--- a/applications/welcome/models/db.py
+++ b/applications/welcome/models/db.py
@@ -62,7 +62,7 @@
 
 ## configure email
 mail = auth.settings.mailer
-mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.sender')
+mail.settings.server = 'logging' if request.is_local else myconf.take('smtp.server')
 mail.settings.sender = myconf.take('smtp.sender')
 mail.settings.login = myconf.take('smtp.login')
 


Test patch:
Repository: web2py/web2py

Issue:
Expose typing
Version 2.10.4-beta+timestamp.2015.04.20.18.00.31

gluon/tools.py
class Expose(object):
line 5365:
self.args = [arg for arg in current.request.args if args] 

needs to be:
self.args = [arg for arg in current.request.args if arg]



Discussion:

Resolving patch:
diff --git a/gluon/tools.py b/gluon/tools.py
--- a/gluon/tools.py
+++ b/gluon/tools.py
@@ -5362,7 +5362,7 @@ def static():
         if current.request.raw_args:
             self.args = [arg for arg in current.request.raw_args.split('/') if arg]
         else:
-            self.args = [arg for arg in current.request.args if args]
+            self.args = [arg for arg in current.request.args if arg]
         filename = os.path.join(base, *self.args)
         if not os.path.exists(filename):
             raise HTTP(404, "FILE NOT FOUND")


Test patch:
Repository: web2py/web2py

Issue:
'exposes' and 'edit views' order in editor
I suggest to change 'exposes' and 'edit views' order in editor to alphabetic.

web2py user google group thread:
https://groups.google.com/forum/#!msg/web2py/eY7g2apCK7w/Bj2_L9gm_HEJ



Discussion:

Resolving patch:
diff --git a/applications/admin/controllers/default.py b/applications/admin/controllers/default.py
--- a/applications/admin/controllers/default.py
+++ b/applications/admin/controllers/default.py
@@ -744,7 +744,7 @@ def edit():
             viewlist.append(aviewpath + '.html')
         if len(viewlist):
             editviewlinks = []
-            for v in viewlist:
+            for v in sorted(viewlist):
                 vf = os.path.split(v)[-1]
                 vargs = "/".join([viewpath.replace(os.sep, "/"), vf])
                 editviewlinks.append(A(vf.split(".")[0],
@@ -754,6 +754,7 @@ def edit():
     if len(request.args) > 2 and request.args[1] == 'controllers':
         controller = (request.args[2])[:-3]
         functions = find_exposed_functions(data)
+        functions = functions and sorted(functions) or []
     else:
         (controller, functions) = (None, None)
 
@@ -1067,7 +1068,7 @@ def design():
     for c in controllers:
         data = safe_read(apath('%s/controllers/%s' % (app, c), r=request))
         items = find_exposed_functions(data)
-        functions[c] = items
+        functions[c] = items and sorted(items) or []
 
     # Get all views
     views = sorted(
@@ -1205,7 +1206,7 @@ def plugin():
     for c in controllers:
         data = safe_read(apath('%s/controllers/%s' % (app, c), r=request))
         items = find_exposed_functions(data)
-        functions[c] = items
+        functions[c] = items and sorted(items) or []
 
     # Get all views
     views = sorted(


Test patch:
Repository: web2py/web2py

Issue:
Deadlock in cache.py/CacheOnDisk in R 2.10.4
found a blocking issue in our app with some image download after upgrading from 2.9.12 to 2.10.4
deadlock in CacheOnDisk class in case of exception in our cache callback function, normally handled in our app
without any issue until now.

the new file_locks introduced in 2.10.1, (3e46e985bf15) acquired before the cache app callback ( value = f() )
with self.storage.acquire(CacheAbstract.cache_stats_name) 
Is never released in case of exception in f()
then next call to the CacheOnDisk during same request will block the thread indefinitely.

(CacheInRam should not have the same issue as self.locker.release() is released before f())
- proposed fix to follow

Bernard Letourmy



Discussion:

Resolving patch:
diff --git a/gluon/cache.py b/gluon/cache.py
--- a/gluon/cache.py
+++ b/gluon/cache.py
@@ -473,9 +473,14 @@ def inc_misses(v):
         if item and ((dt is None) or (item[0] > now - dt)):
             value = item[1]
         else:
-            value = f()
+            try:
+                value = f()
+            except:
+                self.storage.release(CacheAbstract.cache_stats_name)
+                self.storage.release(key)
+                raise
             self.storage[key] = (now, value)
-            self.storage.safe_apply(CacheAbstract.cache_stats_name, inc_misses, 
+            self.storage.safe_apply(CacheAbstract.cache_stats_name, inc_misses,
                                     default_value={'hit_total': 0, 'misses': 0})
 
         self.storage.release(CacheAbstract.cache_stats_name)


Test patch:
Repository: web2py/web2py

Issue:
`response.render()` uses the original `response.view`
## The problem

When using `response.render()`, Web2py works fine for the first request. But it uses wrong view name in subsequent requests.

My same code worked in v2.9.11.
## The scenario

I use views to render parts of my page in this way:

```
def my_action():
    my_div = response.render('div_layout.html')
    # more code...
    return dict(my_div=my_div, other_vars=...)
```

Web2py must use these views:
1. `div_layout.html` in the explicit `response.render()` call;
2. `my_action.html` to show the result of this action, after returning to the caller.
## What is happening

The right scenario (the first time I call the URL):

| `response.view` contents | when |
| --- | --- |
| my_controller/my_view.html | `my_action` starts |
| div_layout.html | in `response.render` |
| my_controller/my_view.html | in `compileapp.run_view_in()`, after `my_action` |

The wrong scenario (in subsequent requests. Pay attention to the second line in table below):

| `response.view` contents | when |
| --- | --- |
| my_controller/my_view.html | `my_action` starts |
| my_controller/my_view.html | in `response.render` |
| my_controller/my_view.html | in `compileapp.run_view_in()`, after `my_action` |



Discussion:

Resolving patch:
diff --git a/gluon/compileapp.py b/gluon/compileapp.py
--- a/gluon/compileapp.py
+++ b/gluon/compileapp.py
@@ -652,7 +652,7 @@ def run_view_in(environment):
     """
     request = current.request
     response = current.response
-    view = response.view
+    view = environment['response'].view
     folder = request.folder
     path = pjoin(folder, 'compiled')
     badv = 'invalid view (%s)' % view


Test patch:
Repository: web2py/web2py

Issue:
request.is_shell and request.is_scheduler are not set properly
When the shell or scheduler are being run, these two request attributes are set, but not to the correct value (which should be False rather than None). And when the shell or scheduler are being run, these two attributes are not set at all (which results in None being returned). So, as it stands, request.is_shell and request.is_scheduler always return None.

The problem is that these attributes are set in gluon.main.wsgibase, which is only called for HTTP requests, but not when the shell or a scheduler task are being run.

Fix:

In gluon.main.wsgibase at https://github.com/web2py/web2py/blob/master/gluon/main.py#L373:

```
                is_shell = True if cmd_opts and cmd_opts.shell else False,
                is_sheduler = True if cmd_opts and cmd_opts.scheduler else False,
```

Actually, in wsgibase, I think these would always be False, so maybe just set each to False.

In gluon.shell.env at https://github.com/web2py/web2py/blob/master/gluon/shell.py#L131, add:

```
request.is_shell = global_settings.cmd_options.shell is not None
request.is_scheduler = global_settings.cmd_options.scheduler is not None
```



Discussion:

Resolving patch:
diff --git a/gluon/main.py b/gluon/main.py
--- a/gluon/main.py
+++ b/gluon/main.py
@@ -370,8 +370,8 @@ def wsgibase(environ, responder):
                     cid = env.http_web2py_component_element,
                     is_local = (env.remote_addr in local_hosts and
                                 client == env.remote_addr),
-                    is_shell = cmd_opts and cmd_opts.shell,
-                    is_sheduler = cmd_opts and cmd_opts.scheduler,
+                    is_shell = False,
+                    is_scheduler = False,
                     is_https = env.wsgi_url_scheme in HTTPS_SCHEMES or \
                         request.env.http_x_forwarded_proto in HTTPS_SCHEMES \
                         or env.https == 'on'
diff --git a/gluon/shell.py b/gluon/shell.py
--- a/gluon/shell.py
+++ b/gluon/shell.py
@@ -129,6 +129,8 @@ def env(
     if global_settings.cmd_options:
         ip = global_settings.cmd_options.ip
         port = global_settings.cmd_options.port
+        request.is_shell = global_settings.cmd_options.shell is not None
+        request.is_scheduler = global_settings.cmd_options.scheduler is not None
     else:
         ip, port = '127.0.0.1', '8000'
     request.env.http_host = '%s:%s' % (ip, port)


Test patch:
Repository: web2py/web2py

Issue:
alignment of readonly fields in forms
https://groups.google.com/forum/#!topic/web2py/6Qbcr8nuey8



Discussion:

Resolving patch:
diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py
--- a/gluon/sqlhtml.py
+++ b/gluon/sqlhtml.py
@@ -938,6 +938,8 @@ 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'] = 'control-label %s' % label_col_class
 


Test patch:
Repository: web2py/web2py

Issue:
Auth.login() sets the minimum password length to 0, but does not restore it. No password validation for auth.register() if defined after auth.login()
_From [markruol..._at_gmail.com](https://code.google.com/u/114619454780239522399/) on August 29, 2014 18:27:44_

What steps will reproduce the problem? 1. Have both auth.register() and auth.login() in the same controller function (define auth.login() first)
2. Submit the register form with errors--there is no password validation
3. This is because auth.login() will set the minimum password length to 0, but won't restore it) https://groups.google.com/forum/#!topic/web2py/13gozLyE3Eo What is the expected output? What do you see instead? Password validation should occur, but it does not.

_Original issue: http://code.google.com/p/web2py/issues/detail?id=1971_



Discussion:

Resolving patch:
diff --git a/gluon/tools.py b/gluon/tools.py
--- a/gluon/tools.py
+++ b/gluon/tools.py
@@ -2898,6 +2898,11 @@ def register(self,
 
         passfield = self.settings.password_field
         formstyle = self.settings.formstyle
+        try: # Make sure we have our original minimum length as other auth forms change it
+            table_user[passfield].requires[-1].min_length = self.settings.password_min_length
+        except:
+            pass
+
         if self.settings.register_verify_password:            
             if self.settings.register_fields is None:
                 self.settings.register_fields = [f.name for f in table_user if f.writable]
@@ -4212,6 +4217,7 @@ def wiki(self,
                               function=function,
                               groups=groups)
         else:
+            self._wiki.settings.extra = extra or {}
             self._wiki.env.update(env or {})
 
         # if resolve is set to True, process request as wiki call


Test patch:
Repository: web2py/web2py

Issue:
Remove timezone option from IS_DATE
Briefly, (1) the current implementation is broken, and (2) there is no clear way to implement timezone transformations with dates (as opposed to datetimes). For further discussion, see https://groups.google.com/forum/#!topic/web2py-developers/-gVGhnTejsU.



Discussion:

Resolving patch:
diff --git a/gluon/validators.py b/gluon/validators.py
--- a/gluon/validators.py
+++ b/gluon/validators.py
@@ -2165,29 +2165,22 @@ class IS_DATE(Validator):
             INPUT(_type='text', _name='name', requires=IS_DATE())
 
     date has to be in the ISO8960 format YYYY-MM-DD
-    timezome must be None or a pytz.timezone("America/Chicago") object
     """
 
     def __init__(self, format='%Y-%m-%d',
-                 error_message='Enter date as %(format)s',
-                 timezone=None):
+                 error_message='Enter date as %(format)s'):
         self.format = translate(format)
         self.error_message = str(error_message)
-        self.timezone = timezone
         self.extremes = {}
 
     def __call__(self, value):
         ovalue = value
         if isinstance(value, datetime.date):
-            if self.timezone is not None:
-                value = value - datetime.timedelta(seconds=self.timezone*3600)
             return (value, None)
         try:
             (y, m, d, hh, mm, ss, t0, t1, t2) = \
                 time.strptime(value, str(self.format))
             value = datetime.date(y, m, d)
-            if self.timezone is not None:
-                value = self.timezone.localize(value).astimezone(utc)
             return (value, None)
         except:
             self.extremes.update(IS_DATETIME.nice(self.format))
@@ -2203,11 +2196,7 @@ def formatter(self, value):
         format = format.replace('%Y', y)
         if year < 1900:
             year = 2000
-        if self.timezone is not None:
-            d = datetime.datetime(year, value.month, value.day)
-            d = d.replace(tzinfo=utc).astimezone(self.timezone)
-        else:
-            d = datetime.date(year, value.month, value.day)
+        d = datetime.date(year, value.month, value.day)
         return d.strftime(format)
 
 
@@ -2307,8 +2296,7 @@ def __init__(self,
                  minimum=None,
                  maximum=None,
                  format='%Y-%m-%d',
-                 error_message=None,
-                 timezone=None):
+                 error_message=None):
         self.minimum = minimum
         self.maximum = maximum
         if error_message is None:
@@ -2320,8 +2308,7 @@ def __init__(self,
                 error_message = "Enter date in range %(min)s %(max)s"
         IS_DATE.__init__(self,
                          format=format,
-                         error_message=error_message,
-                         timezone=timezone)
+                         error_message=error_message)
         self.extremes = dict(min=self.formatter(minimum),
                              max=self.formatter(maximum))
 


Test patch:
Repository: web2py/web2py

Issue:
request.vars not set by routes_in query string.
_From [iiijjj..._at_gmail.com](https://code.google.com/u/103627055288160163786/) on September 26, 2014 16:59:57_

What steps will reproduce the problem? 1. Define a route in routes_in that sets a query string.
2. Access a page that will be routed.
3. Check the value of request.vars. It is not set.

Here is sample code:

routes.py
    routes_in = (
        (BASE + '/$anything', '/welcome/default/index?aaa=111&bbb=222'),
        ...
        )

Then in applications/welcome/views/default/index.html

```
\<div>
    vars: {{=request.vars}}
    \<br>
    env: {{=request.env.query_string}}
\</div>
```

Then visit the welcome app, request.vars displays empty but request.env.query_string is set to 'aaa=111&bbb=222' What is the expected output? What do you see instead? request.vars should be set to 'aaa=111&bbb=222' What version of the product are you using? On what operating system? Tested with: Version 2.9.11-stable+timestamp.2014.09.15.23.35.11

_Original issue: http://code.google.com/p/web2py/issues/detail?id=1990_



Discussion:

Resolving patch:
diff --git a/gluon/globals.py b/gluon/globals.py
--- a/gluon/globals.py
+++ b/gluon/globals.py
@@ -208,7 +208,7 @@ def __init__(self, env):
     def parse_get_vars(self):
         """Takes the QUERY_STRING and unpacks it to get_vars
         """
-        query_string = self.env.get('QUERY_STRING', '')
+        query_string = self.env.get('query_string', '')
         dget = urlparse.parse_qs(query_string, keep_blank_values=1)  # Ref: https://docs.python.org/2/library/cgi.html#cgi.parse_qs
         get_vars = self._get_vars = Storage(dget)
         for (key, value) in get_vars.iteritems():


Test patch:
Repository: web2py/web2py

Issue:
service does not start
because thereis syntax error in file scripts/service/service.py on line 95:

``` python
        if 'log_filename' in config.key():
```

but must

``` python
        if 'log_filename' in config.keys():
```

and on line 77:

``` python
                interfaces.append('%s:%s:%s:%s' % (ip, port, cert, key))
```

but must

``` python
                interfaces.append('%s:%s:%s:%s' % (ip, port, key, cert)
```



Discussion:

Resolving patch:
diff --git a/scripts/service/service.py b/scripts/service/service.py
--- a/scripts/service/service.py
+++ b/scripts/service/service.py
@@ -74,7 +74,7 @@ def load_configuration(self):
             key = config['https_key']
             cert = config['https_cert']
             if key != '' and cert != '':
-                interfaces.append('%s:%s:%s:%s' % (ip, port, cert, key))
+                interfaces.append('%s:%s:%s:%s' % (ip, port, key, cert))
                 ports.append(ports)
         if len(interfaces) == 0:
             sys.exit('Configuration error. Must have settings for http and/or https')
@@ -92,7 +92,7 @@ def load_configuration(self):
         interfaces = ';'.join(interfaces)
         args.append('--interfaces=%s' % interfaces)
 
-        if 'log_filename' in config.key():
+        if 'log_filename' in config.keys():
             log_filename = config['log_filename']
             args.append('--log_filename=%s' % log_filename)
 


Test patch: