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

Issue:
Restore peewee support after incompatible changes
Flask-Admin fails to run with latest release of peewee. Moreover, extra "internal" changes are introduced 
in development version: https://github.com/coleifer/peewee/commit/50c9c1dd24b7a4c48a396a9f5e88f3ea1647859a

Here's a quick fix:
https://github.com/rudyryk/flask-admin/commit/43232f2b4df54f87bd4b507f05d492503e71db06

I'd suggest to wait for the next peewee release before adding final update to Flask-Admin.



Discussion:
That fix looks good for backwards compatibility. Feel free to submit a pull request for it.

@pawl Sure! Thank you :)


Resolving patch:
diff --git a/flask_admin/contrib/peewee/tools.py b/flask_admin/contrib/peewee/tools.py
--- a/flask_admin/contrib/peewee/tools.py
+++ b/flask_admin/contrib/peewee/tools.py
@@ -1,10 +1,5 @@
-from peewee import PrimaryKeyField
-
-
 def get_primary_key(model):
-    for n, f in model._meta.get_sorted_fields():
-        if type(f) == PrimaryKeyField or f.primary_key:
-            return n
+    return model._meta.primary_key.name
 
 
 def parse_like_term(term):
diff --git a/flask_admin/contrib/peewee/view.py b/flask_admin/contrib/peewee/view.py
--- a/flask_admin/contrib/peewee/view.py
+++ b/flask_admin/contrib/peewee/view.py
@@ -2,7 +2,7 @@
 
 from flask import flash
 
-from flask_admin._compat import string_types
+from flask_admin._compat import string_types, iteritems
 from flask_admin.babel import gettext, ngettext, lazy_gettext
 from flask_admin.model import BaseModelView
 from flask_admin.model.form import wrap_fields_in_fieldlist
@@ -149,7 +149,7 @@ def _get_model_fields(self, model=None):
         if model is None:
             model = self.model
 
-        return model._meta.get_sorted_fields()
+        return iteritems(model._meta.fields)
 
     def scaffold_pk(self):
         return get_primary_key(self.model)


Test patch:
Repository: flask-admin/flask-admin

Issue:
Boolean filters options (Yes/No) aren't localized
I'm using the pt-br localizations:

![screenshot from 2015-11-29 15 24 46](https://cloud.githubusercontent.com/assets/3682178/11458749/7e13f9c6-96ad-11e5-9bfc-6e0bb4892146.png)

I checked the localization page at the crowdin site and both of those entries are defined in there, and IIRC, the translations are old enough to be included in the current build.



Discussion:

Resolving patch:
diff --git a/flask_admin/model/base.py b/flask_admin/model/base.py
--- a/flask_admin/model/base.py
+++ b/flask_admin/model/base.py
@@ -23,7 +23,7 @@
 from flask_admin.tools import rec_getattr
 from flask_admin._backwards import ObsoleteAttr
 from flask_admin._compat import (iteritems, itervalues, OrderedDict,
-                                 as_unicode, csv_encode)
+                                 as_unicode, csv_encode, text_type)
 from .helpers import prettify_name, get_mdict_item_or_list
 from .ajax import AjaxModelLoader
 from .fields import ListEditableFieldList
@@ -78,6 +78,10 @@ def non_lazy(self):
         for item in self.filters:
             copy = dict(item)
             copy['operation'] = as_unicode(copy['operation'])
+            options = copy['options']
+            if options:
+                copy['options'] = [(k, text_type(v)) for k, v in options]
+
             filters.append(copy)
         return as_unicode(self.label), filters
 
@@ -735,7 +739,6 @@ def _refresh_filters_cache(self):
                 key = as_unicode(flt.name)
                 if key not in self._filter_groups:
                     self._filter_groups[key] = FilterGroup(flt.name)
-
                 self._filter_groups[key].append({
                     'index': i,
                     'arg': self.get_filter_arg(i, flt),
diff --git a/flask_admin/model/filters.py b/flask_admin/model/filters.py
--- a/flask_admin/model/filters.py
+++ b/flask_admin/model/filters.py
@@ -1,7 +1,6 @@
 import time
 import datetime
 
-from flask_admin._compat import text_type
 from flask_admin.babel import lazy_gettext
 
 
@@ -39,7 +38,7 @@ def get_options(self, view):
             if callable(options):
                 options = options()
 
-            return [(v, text_type(n)) for v, n in options]
+            return options
 
         return None
 


Test patch:
diff --git a/flask_admin/tests/test_model.py b/flask_admin/tests/test_model.py
--- a/flask_admin/tests/test_model.py
+++ b/flask_admin/tests/test_model.py
@@ -326,14 +326,14 @@ def test_column_filters():
 def test_filter_list_callable():
     app, admin = setup()
 
-    flt = SimpleFilter('test', options=lambda: (('1', 'Test 1'), ('2', 'Test 2')))
+    flt = SimpleFilter('test', options=lambda: [('1', 'Test 1'), ('2', 'Test 2')])
 
     view = MockModelView(Model, column_filters=[flt])
     admin.add_view(view)
 
     opts = flt.get_options(view)
     eq_(len(opts), 2)
-    eq_(opts, [('1', u'Test 1'), ('2', u'Test 2')])
+    eq_(opts, [('1', 'Test 1'), ('2', 'Test 2')])
 
 
 def test_form():
Repository: flask-admin/flask-admin

Issue:
Bootstrap model template assumes primary key column name.
I found it because the link for 'view detail' was broken in 'edit' page. I am using `tablename_id` as a primary key. 

https://github.com/flask-admin/flask-admin/search?utf8=%E2%9C%93&q=%22model.id%22&type=Code



Discussion:

Resolving patch:
diff --git a/flask_admin/model/base.py b/flask_admin/model/base.py
--- a/flask_admin/model/base.py
+++ b/flask_admin/model/base.py
@@ -1927,7 +1927,6 @@ def details_view(self):
                            model=model,
                            details_columns=self._details_columns,
                            get_value=self.get_list_value,
-                           get_pk_value=self.get_pk_value,
                            return_url=return_url)
 
     @expose('/delete/', methods=('POST',))


Test patch:
Repository: flask-admin/flask-admin

Issue:
Recent commits broke support for hybrid properties expressions
For instance:

```
@hybrid_property
def foo(self):
    return some_value

@foo.expression
    return select(...)
```

No longer works. It seems contrib/sqla/view/get_list_columns (and maybe related methods) can't handle the "select" type that is being returned by the expression. This used to work. I suggest adding a test for it.

To be more specific, it worked before: https://github.com/flask-admin/flask-admin/commit/459010b0def9da74836f1379126434c5f922ba0c



Discussion:
Alright I think I fixed it. Will send a issue a pull request later.


Resolving patch:
diff --git a/flask_admin/contrib/sqla/view.py b/flask_admin/contrib/sqla/view.py
--- a/flask_admin/contrib/sqla/view.py
+++ b/flask_admin/contrib/sqla/view.py
@@ -484,7 +484,10 @@ def get_sortable_columns(self):
                                     "Failed on: {0}".format(c))
                 else:
                     # column is in same table, use only model attribute name
-                    column_name = column.key
+                    if getattr(column, 'key') is not None:
+                        column_name = column.key
+                    else:
+                        column_name = text_type(c)
 
                 # column_name must match column_name used in `get_list_columns`
                 result[column_name] = column
@@ -517,7 +520,10 @@ def get_list_columns(self):
                     column_name = text_type(c)
                 else:
                     # column is in same table, use only model attribute name
-                    column_name = column.key
+                    if getattr(column, 'key') is not None:
+                        column_name = column.key
+                    else:
+                        column_name = text_type(c)
 
                 visible_name = self.get_column_name(column_name)
 


Test patch:
Repository: flask-admin/flask-admin

Issue:
[Mongoengine] Inner field error for `ListField(EmbeddedDocumentField(Model))`
eg. `users = ListField(EmbeddedDocumentField(User))`

Assuming `User` has a required field that is missing or an URL field that is invalid, on form submit it doesnt display field errors, instead raises the following:

```
Traceback (most recent call last):
  File "/env/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/env/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/env/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/env/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/env/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/env/src/flask-admin/flask_admin/base.py", line 68, in inner
    return self._run_view(f, *args, **kwargs)
  File "/env/src/flask-admin/flask_admin/base.py", line 344, in _run_view
    return fn(self, *args, **kwargs)
  File "/env/src/flask-admin/flask_admin/model/base.py", line 1365, in edit_view
    if self.update_model(form, model):
  File "/env/src/flask-admin/flask_admin/contrib/mongoengine/view.py", line 538, in update_model
    error=format_error(ex)),
  File "/env/src/flask-admin/flask_admin/contrib/mongoengine/helpers.py", line 35, in format_error
    return '. '.join(itervalues(error.to_dict()))
TypeError: sequence item 0: expected string, dict found
```

Sample value for `error.to_dict()` in this scenario:
`{'users': {0: {'url': u'Invalid URL: 123'}}}`



Discussion:

Resolving patch:
diff --git a/flask_admin/contrib/mongoengine/helpers.py b/flask_admin/contrib/mongoengine/helpers.py
--- a/flask_admin/contrib/mongoengine/helpers.py
+++ b/flask_admin/contrib/mongoengine/helpers.py
@@ -1,4 +1,5 @@
 from mongoengine import ValidationError
+from wtforms.validators import ValidationError as wtfValidationError
 from flask_admin._compat import itervalues, as_unicode
 
 
@@ -31,6 +32,9 @@ def make_thumb_args(value):
 
 def format_error(error):
     if isinstance(error, ValidationError):
+        return as_unicode(error)
+
+    if isinstance(error, wtfValidationError):
         return '. '.join(itervalues(error.to_dict()))
 
     return as_unicode(error)


Test patch:
Repository: flask-admin/flask-admin

Issue:
How can we filter selectable values in a form drop down?
I have a form and i want to view only selective field in that form.
Can anyone lead me to the right path.
Thanks in advance :)



Discussion:

Resolving patch:
diff --git a/examples/sqla-filter-selectable/__init__.py b/examples/sqla-filter-selectable/__init__.py
new file mode 100644
diff --git a/examples/sqla-filter-selectable/app.py b/examples/sqla-filter-selectable/app.py
new file mode 100644
--- /dev/null
+++ b/examples/sqla-filter-selectable/app.py
@@ -0,0 +1,88 @@
+from flask import Flask
+from flask_sqlalchemy import SQLAlchemy
+
+import flask_admin as admin
+from flask_admin.contrib import sqla
+
+# Create application
+app = Flask(__name__)
+
+# Create dummy secrey key so we can use sessions
+app.config['SECRET_KEY'] = '123456790'
+
+# Create in-memory database
+app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///sample_db_3.sqlite'
+app.config['SQLALCHEMY_ECHO'] = True
+db = SQLAlchemy(app)
+
+
+# Flask views
+@app.route('/')
+def index():
+    return '<a href="/admin/">Click me to get to Admin!</a>'
+
+
+class Person(db.Model):
+    id = db.Column(db.Integer, primary_key=True)
+    name = db.Column(db.String(50))
+    pets = db.relationship('Pet', backref='person')
+
+    def __unicode__(self):
+        return self.name
+
+
+class Pet(db.Model):
+    id = db.Column(db.Integer, primary_key=True)
+    name = db.Column(db.String(50))
+    person_id = db.Column(db.Integer, db.ForeignKey('person.id'))
+    available = db.Column(db.Boolean)
+
+    def __unicode__(self):
+        return self.name
+
+
+class PersonAdmin(sqla.ModelView):
+    """ Override ModelView to filter options available in forms. """
+
+    def create_form(self):
+        return self._use_filtered_parent(
+            super(PersonAdmin, self).create_form()
+        )
+
+    def edit_form(self, obj):
+        return self._use_filtered_parent(
+            super(PersonAdmin, self).edit_form(obj)
+        )
+
+    def _use_filtered_parent(self, form):
+        form.pets.query_factory = self._get_parent_list
+        return form
+
+    def _get_parent_list(self):
+        # only show available pets in the form
+        return Pet.query.filter_by(available=True).all()
+
+    def __unicode__(self):
+        return self.name
+
+
+# Create admin
+admin = admin.Admin(app, name='Example: SQLAlchemy - Filtered Form Selectable',
+                    template_mode='bootstrap3')
+admin.add_view(PersonAdmin(Person, db.session))
+admin.add_view(sqla.ModelView(Pet, db.session))
+
+if __name__ == '__main__':
+    # Recreate DB
+    db.drop_all()
+    db.create_all()
+
+    person = Person(name='Bill')
+    pet1 = Pet(name='Dog', available=True)
+    pet2 = Pet(name='Fish', available=True)
+    pet3 = Pet(name='Ocelot', available=False)
+    db.session.add_all([person, pet1, pet2, pet3])
+    db.session.commit()
+
+    # Start app
+    app.run(debug=True)


Test patch:
Repository: flask-admin/flask-admin

Issue:
Named filters and i18n doesn't work together
Named filters doesn't work with i18n.

When I add a filter like `flt1_id_equals=10`, it works fine, but the url generator (`BaseModelView._get_list_url`) return the filter as `flt1_id_igual=10` (`igual` is `equals` in `pt-br`).

It affects both pagination and sorting.



Discussion:

Resolving patch:
diff --git a/flask_admin/model/base.py b/flask_admin/model/base.py
--- a/flask_admin/model/base.py
+++ b/flask_admin/model/base.py
@@ -1117,7 +1117,15 @@ def get_filter_arg(self, index, flt):
                 Filter instance
         """
         if self.named_filter_urls:
-            name = ('%s %s' % (flt.name, as_unicode(flt.operation()))).lower()
+            operation = flt.operation()
+
+            try:
+                # get lazy string original value
+                operation = operation._args[0]
+            except AttributeError:
+                pass
+
+            name = ('%s %s' % (flt.name, as_unicode(operation))).lower()
             name = filter_char_re.sub('', name)
             name = filter_compact_re.sub('_', name)
             return name


Test patch:
diff --git a/flask_admin/tests/sqla/test_basic.py b/flask_admin/tests/sqla/test_basic.py
--- a/flask_admin/tests/sqla/test_basic.py
+++ b/flask_admin/tests/sqla/test_basic.py
@@ -1834,6 +1834,28 @@ def test_locale(locale):
     for locale in locales:
         test_locale(locale)
 
+
+def test_modelview_named_filter_localization():
+    app, db, admin = setup()
+
+    app.config['BABEL_DEFAULT_LOCALE'] = 'de'
+    Babel(app)
+
+    Model1, _ = create_models(db)
+
+    view = CustomModelView(
+        Model1, db.session,
+        named_filter_urls=True,
+        column_filters=['test1'],
+    )
+
+    filters = view.get_filters()
+    flt = filters[2]
+    with app.test_request_context():
+        flt_name = view.get_filter_arg(2, flt)
+    eq_('test1_equals', flt_name)
+
+
 def test_custom_form_base():
     app, db, admin = setup()
Repository: flask-admin/flask-admin

Issue:
example sqla not work for saving item with  M2M field value input 
i want to try the example M2M case as below link provided by flask-admin
http://examples.flask-admin.org/sqla/simple/admin/post/new/

when i create new item with tag input, it not work 
User: Jack
Tags: Yellow (if not give a tag, save can work)
....

Error like below 
_Integrity error. (IntegrityError) NOT NULL constraint failed: post.text u'INSERT INTO post (title, text, date, user_id) VALUES (?, ?, ?, ?)' (None, None, None, 4)_



Discussion:

Resolving patch:
diff --git a/examples/sqla/app.py b/examples/sqla/app.py
--- a/examples/sqla/app.py
+++ b/examples/sqla/app.py
@@ -2,6 +2,7 @@
 import os.path as op
 from flask import Flask
 from flask_sqlalchemy import SQLAlchemy
+from future.utils import python_2_unicode_compatible
 
 from wtforms import validators
 
@@ -20,10 +21,12 @@
 app.config['DATABASE_FILE'] = 'sample_db.sqlite'
 app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + app.config['DATABASE_FILE']
 app.config['SQLALCHEMY_ECHO'] = True
-db = SQLAlchemy(app)
+session_options = dict(autoflush=False)
+db = SQLAlchemy(app, session_options=session_options)
 
 
 # Create models
+@python_2_unicode_compatible
 class User(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     first_name = db.Column(db.String(100))
@@ -31,8 +34,7 @@ class User(db.Model):
     username = db.Column(db.String(80), unique=True)
     email = db.Column(db.String(120), unique=True)
 
-    # Required for administrative interface. For python 3 please use __str__ instead.
-    def __unicode__(self):
+    def __str__(self):
         return self.username
 
 
@@ -43,6 +45,7 @@ def __unicode__(self):
                            )
 
 
+@python_2_unicode_compatible
 class Post(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     title = db.Column(db.String(120))
@@ -54,18 +57,20 @@ class Post(db.Model):
 
     tags = db.relationship('Tag', secondary=post_tags_table)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
 
 
+@python_2_unicode_compatible
 class Tag(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     name = db.Column(db.Unicode(64))
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
 
+@python_2_unicode_compatible
 class UserInfo(db.Model):
     id = db.Column(db.Integer, primary_key=True)
 
@@ -75,17 +80,18 @@ class UserInfo(db.Model):
     user_id = db.Column(db.Integer(), db.ForeignKey(User.id))
     user = db.relationship(User, backref='info')
 
-    def __unicode__(self):
+    def __str__(self):
         return '%s - %s' % (self.key, self.value)
 
 
+@python_2_unicode_compatible
 class Tree(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     name = db.Column(db.String(64))
     parent_id = db.Column(db.Integer, db.ForeignKey('tree.id'))
     parent = db.relationship('Tree', remote_side=[id], backref='children')
 
-    def __unicode__(self):
+    def __str__(self):
         return self.name
 
 


Test patch:
Repository: flask-admin/flask-admin

Issue:
Missing translation
There is a missing translation with this string: `Please select model`.
Babel doesn't get it because it's not using gettext directly:

> `placeholder = gettext(field.loader.options.get('placeholder', 'Please select model'))`



Discussion:

Resolving patch:
diff --git a/flask_admin/model/widgets.py b/flask_admin/model/widgets.py
--- a/flask_admin/model/widgets.py
+++ b/flask_admin/model/widgets.py
@@ -58,7 +58,7 @@ def __call__(self, field, **kwargs):
                 kwargs['value'] = data[0]
                 kwargs['data-json'] = json.dumps(data)
 
-        placeholder = gettext(field.loader.options.get('placeholder', 'Please select model'))
+        placeholder = field.loader.options.get('placeholder', gettext('Please select model'))
         kwargs.setdefault('data-placeholder', placeholder)
 
         return HTMLString('<input %s>' % html_params(name=field.name, **kwargs))


Test patch:
Repository: flask-admin/flask-admin

Issue:
sqla/app2.py is broken with python3.5.2
This is under python3.5.2

1) python examples/sqla/app2.py
2) Go to localhost:5000
3) Create new car record
4) Save
5) Select Tyre tab
6) Create new tyre record
7) Note that the Car field is populated with <**main**.Car object at 0x7fe2bef98438>

The same 7 steps work fine on python2.7.12.

Using my rudimentary debugging skills I found that the value is stored in the _view.



Discussion:
It was not converted to python 3.x - you need to change `__unicode__` to `__str__` in the model definition.

I see, thanks for this, I will try to send a PR.


Resolving patch:
diff --git a/examples/sqla/app.py b/examples/sqla/app.py
--- a/examples/sqla/app.py
+++ b/examples/sqla/app.py
@@ -2,7 +2,6 @@
 import os.path as op
 from flask import Flask
 from flask_sqlalchemy import SQLAlchemy
-from future.utils import python_2_unicode_compatible
 
 from wtforms import validators
 
@@ -26,7 +25,6 @@
 
 
 # Create models
-@python_2_unicode_compatible
 class User(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     first_name = db.Column(db.String(100))
@@ -45,7 +43,6 @@ def __str__(self):
                            )
 
 
-@python_2_unicode_compatible
 class Post(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     title = db.Column(db.String(120))
@@ -61,7 +58,6 @@ def __str__(self):
         return self.title
 
 
-@python_2_unicode_compatible
 class Tag(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     name = db.Column(db.Unicode(64))
@@ -70,7 +66,6 @@ def __str__(self):
         return self.name
 
 
-@python_2_unicode_compatible
 class UserInfo(db.Model):
     id = db.Column(db.Integer, primary_key=True)
 
@@ -84,7 +79,6 @@ def __str__(self):
         return '%s - %s' % (self.key, self.value)
 
 
-@python_2_unicode_compatible
 class Tree(db.Model):
     id = db.Column(db.Integer, primary_key=True)
     name = db.Column(db.String(64))
diff --git a/examples/sqla/app2.py b/examples/sqla/app2.py
--- a/examples/sqla/app2.py
+++ b/examples/sqla/app2.py
@@ -28,7 +28,7 @@ class Car(db.Model):
     id = db.Column(db.Integer, primary_key=True, autoincrement=True)
     desc = db.Column(db.String(50))
 
-    def __unicode__(self):
+    def __str__(self):
         return self.desc
 
 


Test patch:
Repository: flask-admin/flask-admin

Issue:
Leaflet JS Errors on examples.flask-admin.org
To reproduce, go here: http://examples.flask-admin.org/geo/admin/multipoint/edit/?url=%2Fgeo%2Fadmin%2Fmultipoint%2F&id=1

and click the "edit layers" icon (above the delete trashcan).

```
Uncaught TypeError: Cannot set property 'previousOptions' of undefined
```

Is this an issue with Leaflet, or something wrong with the flask-admin implementation?



Discussion:

Resolving patch:
diff --git a/examples/geo_alchemy/config.py b/examples/geo_alchemy/config.py
--- a/examples/geo_alchemy/config.py
+++ b/examples/geo_alchemy/config.py
@@ -7,4 +7,8 @@
 
 # credentials for loading map tiles from mapbox
 MAPBOX_MAP_ID = '...'
-MAPBOX_ACCESS_TOKEN = '...'
\ No newline at end of file
+MAPBOX_ACCESS_TOKEN = '...'
+
+# when the creating new shapes, use this default map center
+DEFAULT_CENTER_LAT = -33.918861
+DEFAULT_CENTER_LONG = 18.423300


Test patch: