Skip to content

Commit

Permalink
Fix Slack access token length issue (#3016)
Browse files Browse the repository at this point in the history
# What this PR does

fix the following error caused by too short varchar length of database
fields `access_token` and `bot_access_token` in table
`slack_slackteamidentity`

```
2023-09-12 18:34:07.448 | django.db.utils.DataError: value too long for type character varying(100) |  
-- | -- | --
  |   | 2023-09-12 18:34:07.448 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.448 | return self.cursor.execute(sql, params) |  
  |   | 2023-09-12 18:34:07.448 | File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute |  
  |   | 2023-09-12 18:34:07.448 | raise dj_exc_value.with_traceback(traceback) from exc_value |  
  |   | 2023-09-12 18:34:07.448 | File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 90, in __exit__ |  
  |   | 2023-09-12 18:34:07.448 | with self.db.wrap_database_errors: |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 79, in _execute |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return executor(sql, params, many, context) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 66, in execute |  
  |   | 2023-09-12 18:34:07.447 | cursor.execute(sql, params) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | cursor = super().execute_sql(result_type) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/sql/compiler.py", line 1559, in execute_sql |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return query.get_compiler(self.db).execute_sql(CURSOR) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/query.py", line 802, in _update |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return filtered._update(values) > 0 |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 912, in _do_update |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | updated = self._do_update(base_qs, using, pk_val, values, update_fields, |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 858, in _save_table |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | updated = self._save_table( |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 776, in save_base |  
  |   | 2023-09-12 18:34:07.447 | self.save_base(using=using, force_insert=force_insert, |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 739, in save |  
  |   | 2023-09-12 18:34:07.447 | self.save() |  
  |   | 2023-09-12 18:34:07.447 | File "/etc/app/apps/slack/models/slack_team_identity.py", line 72, in update_oauth_fields |  
  |   | 2023-09-12 18:34:07.447 | slack_team_identity.update_oauth_fields(user, organization, response) |  
  |   | 2023-09-12 18:34:07.447 | File "/etc/app/apps/social_auth/pipeline.py", line 102, in populate_slack_identities |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | result = func(*args, **out) or {} |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/backends/base.py", line 118, in run_pipeline |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/backends/base.py", line 86, in pipeline |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.pipeline(pipeline, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/backends/base.py", line 83, in authenticate |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | user = backend.authenticate(request, **credentials) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/__init__.py", line 76, in authenticate |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return func(*func_args, **func_kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/views/decorators/debug.py", line 42, in sensitive_variables_wrapper |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return authenticate(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_django/strategy.py", line 105, in authenticate |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.strategy.authenticate(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/etc/app/apps/social_auth/backends.py", line 100, in do_auth |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return func(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/utils.py", line 253, in wrapper |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.do_auth(access_token, response=response, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/etc/app/apps/social_auth/backends.py", line 88, in auth_complete |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return func(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/utils.py", line 253, in wrapper |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.auth_complete(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/backends/base.py", line 39, in complete |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | user = backend.complete(user=user, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_core/actions.py", line 49, in do_complete |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | result = do_complete( |  
  |   | 2023-09-12 18:34:07.447 | File "/etc/app/apps/api/views/auth.py", line 52, in overridden_complete_slack_auth |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return func(request, backend, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/social_django/utils.py", line 46, in wrapper |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return view_func(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | response = view_func(request, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return func(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/rest_framework/decorators.py", line 50, in handler |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | response = handler(request, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch |  
  |   | 2023-09-12 18:34:07.447 | raise exc |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception |  
  |   | 2023-09-12 18:34:07.447 | self.raise_uncaught_exception(exc) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | response = self.handle_exception(exc) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.dispatch(request, *args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/views/generic/base.py", line 70, in view |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return view_func(*args, **kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | response = wrapped_callback(request, *callback_args, **callback_kwargs) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/base.py", line 181, in _get_response |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | response = get_response(request) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 47, in inner |  
  |   | 2023-09-12 18:34:07.447 | Traceback (most recent call last): |  
  |   | 2023-09-12 18:34:07.447 |   |  
  |   | 2023-09-12 18:34:07.447 | The above exception was the direct cause of the following exception: |  
  |   | 2023-09-12 18:34:07.447 |   |  
  |   | 2023-09-12 18:34:07.447 |   |  
  |   | 2023-09-12 18:34:07.447 | psycopg2.errors.StringDataRightTruncation: value too long for type character varying(100) |  
  |   | 2023-09-12 18:34:07.447 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |  
  |   | 2023-09-12 18:34:07.447 | return self.cursor.execute(sql, params) |  
  |   | 2023-09-12 18:34:07.447 | File "/usr/local/lib/python3.11/site-packages/django/db/backends/utils.py", line 84, in _execute |  
  |   | 2023-09-12 18:34:07.447 | Traceback (most recent call last): |  
  |   | 2023-09-12 18:34:07.447 | 2023-09-12 10:34:07 source=engine:app google_trace_id=50a15245db9b828e0ab33e8d115dd10a/3838538413005063100 logger=django.request Internal Server Error: /api/internal/v1/complete/slack-install-free/
```

---------

Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
  • Loading branch information
toolchainx and vstpme authored Sep 13, 2023
1 parent 8729d8f commit 0c7281a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Fixed

- Fix Slack access token length issue by @toolchainX ([#3016](https://github.com/grafana/oncall/pull/3016))

## v1.3.37 (2023-09-12)

### Added
Expand Down
23 changes: 23 additions & 0 deletions engine/apps/slack/migrations/0004_auto_20230913_1020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.20 on 2023-09-13 10:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('slack', '0003_delete_slackactionrecord'),
]

operations = [
migrations.AlterField(
model_name='slackteamidentity',
name='access_token',
field=models.CharField(default=None, max_length=255, null=True),
),
migrations.AlterField(
model_name='slackteamidentity',
name='bot_access_token',
field=models.CharField(default=None, max_length=255, null=True),
),
]
4 changes: 2 additions & 2 deletions engine/apps/slack/models/slack_team_identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class SlackTeamIdentity(models.Model):
slack_id = models.CharField(max_length=100)
cached_name = models.CharField(max_length=100, null=True, default=None)
cached_app_id = models.CharField(max_length=100, null=True, default=None)
access_token = models.CharField(max_length=100, null=True, default=None)
access_token = models.CharField(max_length=255, null=True, default=None)
bot_user_id = models.CharField(max_length=100, null=True, default=None)
bot_access_token = models.CharField(max_length=100, null=True, default=None)
bot_access_token = models.CharField(max_length=255, null=True, default=None)
oauth_scope = models.TextField(max_length=30000, null=True, default=None)
detected_token_revoked = models.DateTimeField(null=True, default=None, verbose_name="Deleted At")
is_profile_populated = models.BooleanField(default=False)
Expand Down

0 comments on commit 0c7281a

Please sign in to comment.