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

Issue:
Module name of individual file is its full URL
When javascript files are loaded in the browser directly without concatenation and source maps, the displayed module name is the full URL of the script.

I will create a PR for this in a moment.



Discussion:

Resolving patch:
diff --git a/src/sentry/tasks/fetch_source.py b/src/sentry/tasks/fetch_source.py
--- a/src/sentry/tasks/fetch_source.py
+++ b/src/sentry/tasks/fetch_source.py
@@ -273,6 +273,9 @@ def expand_javascript_source(data, **kwargs):
         # TODO: we're currently running splitlines twice
         if not sourcemap:
             source_code[filename] = (result.body.splitlines(), None)
+            for f in frames:
+                if f.abs_path == filename:
+                    f.module = generate_module(filename)
             continue
         else:
             logger.debug('Found sourcemap %r for minified script %r', sourcemap[:256], result.url)


Test patch:
Repository: getsentry/sentry

Issue:
do we really need 'redis>=2.7.0,<2.9.0' ?
Hi

Recently I was trying to use sentry with [django-redis](https://github.com/niwibe/django-redis) as a cache backend and this can't be (easily) done with current versions of both django-redis and sentry since django-redis has a restriction for [redis>=2.10.0](https://github.com/niwibe/django-redis/blob/fcfd73d85d4fc3350d9cdacdb08546a5f4c9a66d/setup.py#L21). 
A simple installation shows that sentry works fine with `redis==2.10.3` but I guess this would need a more thorough tests. 

I briefly checked redis-py changelog and it seems the only possible backwards incompatible change is [this](https://github.com/andymccurdy/redis-py/blob/54e1040b576afb4155bf839483428c5edac14df0/CHANGES#L9-L15). Also I noticed that current version of sentry has a builtin redis cache backend, but it doesn't seem to cover other potential apps installed within the project. 

I also posted similar issue on niwibe/django-redis#113.



Discussion:
We only lock-in versions to ensure stability. It's just a generic pattern. If you're willing to test against a newer version of Redis feel free to submit a PR and we'll happily update the range.

(That said, it likely works just fine)

At some point in the future everything will likely go through internal Sentry caches, but the only use of it currently is for node preprocessing to lighten queue workloads.

OK. Great. Thanks for your reply. I will try to open a PR for this. Any hints about what should be in there (except the range update itself)?

Range update is probably enough. Basically if test suite passes its probably safe.


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -92,7 +92,7 @@
     'python-dateutil>=1.5.0,<2.0.0',
     'python-memcached>=1.53,<2.0.0',
     'raven>=5.0.0',
-    'redis>=2.7.0,<2.9.0',
+    'redis>=2.7.0,<2.11.0',
     'simplejson>=3.1.0,<3.4.0',
     'six>=1.6.0,<2.0.0',
     'setproctitle>=1.1.7,<1.2.0',


Test patch:
Repository: getsentry/sentry

Issue:
New user with new project
As an admin you can add a new user with a new project and this raises `DoesNotExist: Project has no organization.` because the project created is without a team and organization.

Not sure what team/organization sould be asigned to this new project. Any ideas?



Discussion:
TBH we should probably remove the create project feature here as it no longer makes sense

Otherwise it should Organization.get_default()


Resolving patch:
diff --git a/src/sentry/web/forms/__init__.py b/src/sentry/web/forms/__init__.py
--- a/src/sentry/web/forms/__init__.py
+++ b/src/sentry/web/forms/__init__.py
@@ -42,8 +42,6 @@ class BaseUserForm(forms.ModelForm):
 
 
 class NewUserForm(BaseUserForm):
-    create_project = forms.BooleanField(required=False,
-        help_text=_("Create a project for this user."))
     send_welcome_mail = forms.BooleanField(required=False,
         help_text=_("Send this user a welcome email which will contain their generated password."))
 
diff --git a/src/sentry/web/frontend/admin.py b/src/sentry/web/frontend/admin.py
--- a/src/sentry/web/frontend/admin.py
+++ b/src/sentry/web/frontend/admin.py
@@ -129,25 +129,12 @@ def create_new_user(request):
 
         user.save()
 
-        if form.cleaned_data['create_project']:
-            project = Project.objects.create(
-                name='%s\'s New Project' % user.username.capitalize()
-            )
-            member = project.organization.member_set.get(user=user)
-            key = project.key_set.get(user=user)
-
         if form.cleaned_data['send_welcome_mail']:
             context = {
                 'username': user.username,
                 'password': password,
                 'url': absolute_uri(reverse('sentry')),
             }
-            if form.cleaned_data['create_project']:
-                context.update({
-                    'project': project,
-                    'member': member,
-                    'dsn': key.get_dsn(),
-                })
             body = render_to_string('sentry/emails/welcome_mail.txt', context, request)
 
             try:


Test patch:
Repository: getsentry/sentry

Issue:
Chinese translations are broken in React app
Only values passed through moment.js (datetime library) appear to be doing any translating:

![image](https://cloud.githubusercontent.com/assets/2153/13038534/062d3728-d349-11e5-97a0-a399f0432432.png)

Strings parsed through traditional Django-powered views appear to be translated correctly.

cc @mitsuhiko 



Discussion:

Resolving patch:
diff --git a/src/sentry/templatetags/sentry_assets.py b/src/sentry/templatetags/sentry_assets.py
--- a/src/sentry/templatetags/sentry_assets.py
+++ b/src/sentry/templatetags/sentry_assets.py
@@ -56,5 +56,5 @@ def locale_js_include(context):
     if lang_code == 'en' or lang_code not in settings.SUPPORTED_LANGUAGES:
         return ''
 
-    href = get_asset_url("sentry", "dist/moment/locale/" + lang_code + ".js")
+    href = get_asset_url("sentry", "dist/locale/" + lang_code + ".js")
     return "<script src=\"{0}\"{1}></script>".format(href, crossorigin())


Test patch:
diff --git a/tests/karma.conf.js b/tests/karma.conf.js
--- a/tests/karma.conf.js
+++ b/tests/karma.conf.js
@@ -32,7 +32,8 @@ module.exports = function(config) {
       resolve: {
         alias: {
           'app': appPrefix,
-          sinon: 'sinon/pkg/sinon' // see [1] above
+          sinon: 'sinon/pkg/sinon', // see [1] above
+          'sentry-locale': path.join(__dirname, '..', 'src', 'sentry', 'locale')
         },
         modulesDirectories: ['node_modules'],
         extensions: ['', '.jsx', '.js', '.json']
diff --git a/tests/sentry/templatetags/test_sentry_assets.py b/tests/sentry/templatetags/test_sentry_assets.py
--- a/tests/sentry/templatetags/test_sentry_assets.py
+++ b/tests/sentry/templatetags/test_sentry_assets.py
@@ -17,7 +17,7 @@ def test_supported_foreign_lang(self):
             'request': Mock(LANGUAGE_CODE='fr'),  # French, in locale/catalogs.json
         }))
 
-        assert '<script src="/_static/{version}/sentry/dist/moment/locale/fr.js"></script>' in result
+        assert '<script src="/_static/{version}/sentry/dist/locale/fr.js"></script>' in result
 
     def test_unsupported_foreign_lang(self):
         result = self.TEMPLATE.render(Context({
Repository: getsentry/sentry

Issue:
Create the MessagePack formatter.
Create an application-wide logging formatter that returns dictionaries in the MessagePack format when configured to.

Will be configured by setting `SENTRY_LOGGING_FORMAT = 'msgpack'` in `config.yml`. Intended to be ran on production systems with logging infrastructure in place to receive MessagePack formatted log events.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -110,6 +110,7 @@
     'ipaddr>=2.1.11,<2.2.0',
     'kombu==3.0.30',
     'lxml>=3.4.1',
+    'msgpack-python>=0.4,<0.5',
     'mock>=0.8.0,<1.1',
     'petname>=1.7,<1.8',
     'Pillow>=3.2.0,<3.3.0',
diff --git a/src/sentry/logging/__init__.py b/src/sentry/logging/__init__.py
new file mode 100644
--- /dev/null
+++ b/src/sentry/logging/__init__.py
@@ -0,0 +1,8 @@
+"""
+sentry.logging
+~~~~~~~~~~~~~~
+:copyright: (c) 2010-2016 by the Sentry Team, see AUTHORS for more details.
+:license: BSD, see LICENSE for more details.
+"""
+
+from __future__ import absolute_import
diff --git a/src/sentry/logging/formatters.py b/src/sentry/logging/formatters.py
new file mode 100644
--- /dev/null
+++ b/src/sentry/logging/formatters.py
@@ -0,0 +1,31 @@
+"""
+sentry.logging.formatters
+~~~~~~~~~~~~~~~~~~~~~~~~~
+:copyright: (c) 2010-2016 by the Sentry Team, see AUTHORS for more details.
+:license: BSD, see LICENSE for more details.
+"""
+
+from __future__ import absolute_import
+
+from logging import Formatter
+from traceback import format_tb
+
+from django.utils.encoding import force_bytes
+from msgpack import packb
+
+
+class MessagePackFormatter(Formatter):
+    """
+    Return a packed dictionary.
+
+    Will pack the dictionary or the String representation of the message.
+    """
+    def format(self, record):
+        pack = record.msg if isinstance(record.msg, dict) else {
+            'msg': force_bytes(record.msg, errors='replace')
+        }
+        pack['levelname'] = record.levelname
+        if record.exc_info:
+            pack['traceback'] = format_tb(record.exc_info[-1])
+
+        return packb(pack)


Test patch:
Repository: getsentry/sentry

Issue:
TagDistributionMeter blows up if tag values include newline characters
We've observed some users who are passing newline characters in their recorded tag values, which are being returned from the API (for `/issues/releases/<release>/tags/`):

```
name: "build-2609↵"
```

These values are being set as keys for React nodes, which causes them to explode.



Discussion:
@dcramer has commented that the server should validate these values and discard them.


Resolving patch:
diff --git a/src/sentry/coreapi.py b/src/sentry/coreapi.py
--- a/src/sentry/coreapi.py
+++ b/src/sentry/coreapi.py
@@ -30,7 +30,7 @@
 )
 from sentry.interfaces.base import get_interface, InterfaceValidationError
 from sentry.interfaces.csp import Csp
-from sentry.models import EventError, Project, ProjectKey, TagKey
+from sentry.models import EventError, Project, ProjectKey, TagKey, TagValue
 from sentry.tasks.store import preprocess_event
 from sentry.utils import json
 from sentry.utils.auth import parse_auth_header
@@ -510,6 +510,15 @@ def validate_data(self, project, data):
                     })
                     continue
 
+                if not TagValue.is_valid_value(v):
+                    self.log.info('Discard invalid tag value: %s', v)
+                    data['errors'].append({
+                        'type': EventError.INVALID_DATA,
+                        'name': 'tags',
+                        'value': pair,
+                    })
+                    continue
+
                 tags.append((k, v))
             data['tags'] = tags
 
diff --git a/src/sentry/models/tagvalue.py b/src/sentry/models/tagvalue.py
--- a/src/sentry/models/tagvalue.py
+++ b/src/sentry/models/tagvalue.py
@@ -44,6 +44,10 @@ class Meta:
 
     __repr__ = sane_repr('project_id', 'key', 'value')
 
+    @classmethod
+    def is_valid_value(self, value):
+        return '\n' not in value
+
     def get_label(self):
         # HACK(dcramer): quick and dirty way to hack in better display states
         if self.key == 'sentry:user':


Test patch:
diff --git a/tests/sentry/coreapi/tests.py b/tests/sentry/coreapi/tests.py
--- a/tests/sentry/coreapi/tests.py
+++ b/tests/sentry/coreapi/tests.py
@@ -302,6 +302,17 @@ def test_reserved_tags(self):
         assert data['errors'][0]['name'] == 'tags'
         assert data['errors'][0]['value'] == ('release', 'abc123')
 
+    def test_tag_value(self):
+        data = self.helper.validate_data(self.project, {
+            'message': 'foo',
+            'tags': [('foo', 'bar\n'), ('biz', 'baz')],
+        })
+        assert data['tags'] == [('biz', 'baz')]
+        assert len(data['errors']) == 1
+        assert data['errors'][0]['type'] == 'invalid_data'
+        assert data['errors'][0]['name'] == 'tags'
+        assert data['errors'][0]['value'] == ('foo', 'bar\n')
+
     def test_extra_as_string(self):
         data = self.helper.validate_data(self.project, {
             'message': 'foo',
Repository: getsentry/sentry

Issue:
Culprit not shown for iOS
For some iOS events the culprit is not shown in the UI.



Discussion:

Resolving patch:
diff --git a/src/sentry/lang/native/plugin.py b/src/sentry/lang/native/plugin.py
--- a/src/sentry/lang/native/plugin.py
+++ b/src/sentry/lang/native/plugin.py
@@ -96,7 +96,11 @@ def inject_apple_backtrace(data, frames, diagnosis=None, error=None,
         exc = exception_from_apple_error_or_diagnosis(error, diagnosis)
         if exc is not None:
             exc['stacktrace'] = stacktrace
-            data['sentry.interfaces.Exception'] = exc
+            data['sentry.interfaces.Exception'] = {'values': [exc]}
+            # Since we inject the exception late we need to make sure that
+            # we set the event type to error as it would be set to
+            # 'default' otherwise.
+            data['type'] = 'error'
             return
 
     data['sentry.interfaces.Stacktrace'] = stacktrace


Test patch:
Repository: getsentry/sentry

Issue:
Turn the option system.logging-format into an enum.



Discussion:

Resolving patch:
diff --git a/src/sentry/logging/__init__.py b/src/sentry/logging/__init__.py
--- a/src/sentry/logging/__init__.py
+++ b/src/sentry/logging/__init__.py
@@ -6,3 +6,8 @@
 """
 
 from __future__ import absolute_import
+
+
+class LoggingFormat(object):
+    HUMAN = 'human'
+    MACHINE = 'machine'
diff --git a/src/sentry/options/defaults.py b/src/sentry/options/defaults.py
--- a/src/sentry/options/defaults.py
+++ b/src/sentry/options/defaults.py
@@ -7,6 +7,7 @@
 """
 from __future__ import absolute_import, print_function
 
+from sentry.logging import LoggingFormat
 from sentry.options import (
     FLAG_IMMUTABLE, FLAG_NOSTORE, FLAG_PRIORITIZE_DISK, FLAG_REQUIRED, FLAG_ALLOW_EMPTY,
     register,
@@ -26,7 +27,7 @@
 # Absolute URL to the sentry root directory. Should not include a trailing slash.
 register('system.url-prefix', ttl=60, grace=3600, flags=FLAG_REQUIRED | FLAG_PRIORITIZE_DISK)
 register('system.root-api-key', flags=FLAG_PRIORITIZE_DISK)
-register('system.logging-format', default='human', flags=FLAG_PRIORITIZE_DISK)
+register('system.logging-format', default=LoggingFormat.HUMAN, flags=FLAG_PRIORITIZE_DISK)
 
 # Redis
 register(


Test patch:
Repository: getsentry/sentry

Issue:
Don't log empty emails.
We send notifications through django mail that can possibly go out to no one. It's totally fine, but it probably isn't worth logging.



Discussion:

Resolving patch:
diff --git a/src/sentry/utils/email.py b/src/sentry/utils/email.py
--- a/src/sentry/utils/email.py
+++ b/src/sentry/utils/email.py
@@ -379,9 +379,9 @@ def send_async(self, to=None, bcc=None):
             )
             logger.bind(message_id=message.extra_headers['Message-Id'])
             if fmt == LoggingFormat.HUMAN:
-                log_mail_queued(to=self.format_to(to))
+                log_mail_queued(to=self.format_to(message.to))
             elif fmt == LoggingFormat.MACHINE:
-                for recipient in to:
+                for recipient in message.to:
                     log_mail_queued(to=recipient)
 
 


Test patch:
Repository: getsentry/sentry

Issue:
Remove msgpack cruft
Since we bailed on msgpack, we should remove the dependency and anything else left over.



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -111,7 +111,6 @@
     'ipaddr>=2.1.11,<2.2.0',
     'kombu==3.0.30',
     'lxml>=3.4.1',
-    'msgpack-python>=0.4,<0.5',
     'mock>=0.8.0,<1.1',
     'petname>=1.7,<1.8',
     'Pillow>=3.2.0,<3.3.0',


Test patch:
Repository: getsentry/sentry

Issue:
New Auth Tokens cannot pass sudo check
The new auth token based API access never passes sudo:

``` python
def is_considered_sudo(request):
    return request.is_sudo() or \
        isinstance(request.auth, ApiKey)
```



Discussion:
The error from the API:

```
{
  "error": "Account verification required.",
  "sudoRequired": true,
  "username": "foo@bar.com" 
}
```

I suppose if we did it for ApiKey it's likely fine for AuthToken. Was there a specific report of someone wanting to do something that required sudo?

The API documentation lists support for deleting a sentry project (which we are trying to utilize).

When calling HTTP DELETE on API https://app.getsentry.com/api/0/projects/org-slug/project-slug/ with the 'Authorization: Bearer authtoken' header we receive the following response:

Response code:
{
"error": "Account verification required.",
"sudoRequired": true,
"username": "foo@bar.com"
}

Could you describe the use-case for which you want to remove a project via the API? We're a bit paranoid about opening up endpoints like this as they expose easier attack vectors.

One of the configurations for our dev environments is to mirror production and develop directly on AWS (we have a series of tools in place to make this seamless). Recently, as part of the auto-provisioning of the AWS dev environment we started provisioning a GetSentry project to associate with the dev environment. When we auto unprovision the dev environment on AWS it would be nice to clean up the Sentry project associated with it at the same time.


Resolving patch:
diff --git a/src/sentry/api/decorators.py b/src/sentry/api/decorators.py
--- a/src/sentry/api/decorators.py
+++ b/src/sentry/api/decorators.py
@@ -5,12 +5,13 @@
 from django.http import HttpResponse
 from functools import wraps
 
-from sentry.models import ApiKey
+from sentry.models import ApiKey, ApiToken
 
 
 def is_considered_sudo(request):
     return request.is_sudo() or \
-        isinstance(request.auth, ApiKey)
+        isinstance(request.auth, ApiKey) or \
+        isinstance(request.auth, ApiToken)
 
 
 def sudo_required(func):


Test patch:
Repository: getsentry/sentry

Issue:
2FA Improvements
- [ ] add an icon to authy
- [ ] focus the input field automatically on the 2fa page



Discussion:

Resolving patch:
diff --git a/src/sentry/web/forms/accounts.py b/src/sentry/web/forms/accounts.py
--- a/src/sentry/web/forms/accounts.py
+++ b/src/sentry/web/forms/accounts.py
@@ -439,5 +439,6 @@ class TwoFactorForm(forms.Form):
     otp = forms.CharField(
         label=_('One-time password'), max_length=20, widget=forms.TextInput(
             attrs={'placeholder': _('Code from authenticator'),
+                   'autofocus': True,
         }),
     )


Test patch:
Repository: getsentry/sentry

Issue:
Add timestamps back to human log format
For a human, these are valuable, but as a machine, idgaf because I'm stamping my own.



Discussion:

Resolving patch:
diff --git a/src/sentry/logging/handlers.py b/src/sentry/logging/handlers.py
--- a/src/sentry/logging/handlers.py
+++ b/src/sentry/logging/handlers.py
@@ -5,9 +5,11 @@
 :license: BSD, see LICENSE for more details.
 """
 
-from simplejson import JSONEncoder
+
 import logging
 
+from django.utils.timezone import now
+from simplejson import JSONEncoder
 from structlog import get_logger
 from structlog.processors import _json_fallback_handler
 
@@ -44,14 +46,15 @@ def __call__(self, logger, name, event_dict):
             if isinstance(level, basestring)
             else logging.getLevelName(level)
         )
-        base = '[%s] %s: %s' % (
+        base = '%s [%s] %s: %s' % (
+            now().strftime('%H:%M:%S'),
             real_level,
             event_dict.pop('name', 'root'),
             event_dict.pop('event'),
         )
         join = ' '.join(k + '=' + repr(v)
                for k, v in event_dict.iteritems())
-        return '%s (%s)' % (base, join)
+        return '%s%s' % (base, (' (%s)' % join if join else ''))
 
 
 class StructLogHandler(logging.StreamHandler):
diff --git a/src/sentry/runner/commands/devserver.py b/src/sentry/runner/commands/devserver.py
--- a/src/sentry/runner/commands/devserver.py
+++ b/src/sentry/runner/commands/devserver.py
@@ -72,8 +72,8 @@ def devserver(reload, watchers, workers, bind):
             raise click.ClickException('Disable CELERY_ALWAYS_EAGER in your settings file to spawn workers.')
 
         daemons += [
-            ('worker', ['sentry', 'run', 'worker', '-c', '1', '-l', 'INFO', '--autoreload']),
-            ('cron', ['sentry', 'run', 'cron', '-l', 'INFO', '--autoreload']),
+            ('worker', ['sentry', 'run', 'worker', '-c', '1', '--autoreload']),
+            ('cron', ['sentry', 'run', 'cron', '--autoreload']),
         ]
 
     if needs_https and has_https:


Test patch:
Repository: getsentry/sentry

Issue:
Parse the email template contexts for identifiers and log them along with the mail.queued event.
We currently log types of mail sent but do not add any context along with that, so it's easy to see that someone got an email about an event, but since the `event_id` is not passed along, the log event is somewhat useless.



Discussion:
The project ID and group ID would be useful here as well, as well as the triggering rule ID.


Resolving patch:
diff --git a/src/sentry/plugins/bases/notify.py b/src/sentry/plugins/bases/notify.py
--- a/src/sentry/plugins/bases/notify.py
+++ b/src/sentry/plugins/bases/notify.py
@@ -64,19 +64,28 @@ def notify(self, notification):
 
     def rule_notify(self, event, futures):
         rules = []
+        extra = {
+            'event_id': event.id,
+            'group_id': event.group_id,
+            'plugin': self.slug,
+        }
+        log_event = 'dispatched'
         for future in futures:
             rules.append(future.rule)
+            extra['rule_id'] = future.rule.id
             if not future.kwargs:
                 continue
             raise NotImplementedError('The default behavior for notification de-duplication does not support args')
 
         project = event.group.project
+        extra['project_id'] = project.id
         if hasattr(self, 'notify_digest') and digests.enabled(project):
             get_digest_option = lambda key: ProjectOption.objects.get_value(
                 project,
                 get_digest_option_key(self.get_conf_key(), key),
             )
             digest_key = unsplit_key(self, event.group.project)
+            extra['digest_key'] = digest_key
             immediate_delivery = digests.add(
                 digest_key,
                 event_to_record(event, rules),
@@ -85,6 +94,8 @@ def rule_notify(self, event, futures):
             )
             if immediate_delivery:
                 deliver_digest.delay(digest_key)
+            else:
+                log_event = 'digested'
 
         else:
             notification = Notification(
@@ -92,11 +103,8 @@ def rule_notify(self, event, futures):
                 rules=rules,
             )
             self.notify(notification)
-            self.logger.info('notification.dispatched', extra={
-                'event_id': event.id,
-                'plugin': self.slug,
-                'rule_id': rules[0].id if rules else None,
-            })
+
+        self.logger.info('notification.%s' % log_event, extra=extra)
 
     def notify_users(self, group, event, fail_silently=False):
         raise NotImplementedError


Test patch:
Repository: getsentry/sentry

Issue:
Additional sensitive field: credentials
Hello, might I suggest adding one more word to list of default sensitive fields? It would be **credentials**. The Nette PHP framework uses variable of that name by default and it makes quite a lot of sense. I know that we can set additional fields in settings but a) it is cumbersome as we have many projects b) it is not obvious and we found out the hard way.

Reference where the $credentials variable can be seen:
https://github.com/nette/sandbox/blob/master/app/model/UserManager.php#L40


Discussion:

Resolving patch:
diff --git a/src/sentry/constants.py b/src/sentry/constants.py
--- a/src/sentry/constants.py
+++ b/src/sentry/constants.py
@@ -172,6 +172,7 @@ def get_all_languages():
     'apikey',
     'access_token',
     'auth',
+    'credentials',
 )
 
 VALID_PLATFORMS = set([


Test patch: