Re: Error while running '$ python manage.py collectstatic --noinput'.
Here is the static files setting that we have in our settings.py file: *STATIC_URL = '/static/'STATIC_ROOT = os.path.join(BASE_DIR, 'static')* On Saturday, December 16, 2023 at 7:02:46 PM UTC-7 Ram wrote: > Hi, > > Did anyone hit this error before during production server or any type of > deployment. We tried deployment using Digital Oceanś App platform as a > pre-prod deployment to check whether this App platform is feasible for our > Django web site, but we are hitting this error no matter what ever > modification we change in settings.py to avoid this error. Tried a lot of > Google search results to address this issue, but no luck so far. We are > wondering whether anyone has any recommendations on this error. If you did > not try Digital Oceanś app platform, what would be your recommendation for > production server deployment? We are planning to use only app platforms to > avoid infrastructure overhead. > > >> [2023-12-17 01:40:06] │ -> $ python manage.py collectstatic --noinput >> [2023-12-17 01:40:06] │Traceback (most recent call last): >> [2023-12-17 01:40:06] │ File "/workspace/manage.py", line 23, in >> >> [2023-12-17 01:40:06] │execute_from_command_line(sys.argv) >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", >> >> line 446, in execute_from_command_line >> [2023-12-17 01:40:06] │utility.execute() >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", >> >> line 420, in execute >> [2023-12-17 01:40:06] │django.setup() >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/__init__.py", line >> 24, in setup >> [2023-12-17 01:40:06] │apps.populate(settings.INSTALLED_APPS) >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/apps/registry.py", >> line 91, in populate >> [2023-12-17 01:40:06] │app_config = AppConfig.create(entry) >> [2023-12-17 01:40:06] │ ^^^ >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/apps/config.py", >> line 228, in create >> [2023-12-17 01:40:06] │import_module(entry) >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/importlib/__init__.py", line 126, in >> import_module >> [2023-12-17 01:40:06] │return >> _bootstrap._gcd_import(name[level:], package, level) >> [2023-12-17 01:40:06] │ >> >> [2023-12-17 01:40:06] │ File "", >> line 1204, in _gcd_import >> [2023-12-17 01:40:06] │ File "", >> line 1176, in _find_and_load >> [2023-12-17 01:40:06] │ File "", >> line 1147, in _find_and_load_unlocked >> [2023-12-17 01:40:06] │ File "", >> line 690, in _load_unlocked >> [2023-12-17 01:40:06] │ File "> importlib._bootstrap_external>", line 940, in exec_module >> [2023-12-17 01:40:06] │ File "", >> line 241, in _call_with_frames_removed >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/__init__.py", >> >> line 1, in >> [2023-12-17 01:40:06] │from .columns import ( >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/columns/__init__.py", >> >> line 8, in >> [2023-12-17 01:40:06] │from .jsoncolumn import JSONColumn >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/columns/jsoncolumn.py", >> >> line 11, in >> [2023-12-17 01:40:06] │from django.contrib.postgres.fields >> import HStoreField >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/fields/__init__.py", >> >> line 1, in >> [2023-12-17 01:40:06] │from .array import * # NOQA >> [2023-12-17 01:40:06] │ >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/fields/array.py", >> >> line 3, in >> [2023-12-17 01:40:06] │from django.contrib.postgres import >> lookups >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/lookups.py", >> >> line 4, in >> [2023-12-17 01:40:06] │from .search import SearchVector, >> SearchVectorExact, SearchVectorField >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/search.py", >> >> line 1, in >> [2023-12-17 01:40:06] │import psycopg2 >> [2023-12-17 01:40:06] │ File >> "/app/.heroku/python/lib/
Error while running '$ python manage.py collectstatic --noinput'.
Hi, Did anyone hit this error before during production server or any type of deployment. We tried deployment using Digital Oceanś App platform as a pre-prod deployment to check whether this App platform is feasible for our Django web site, but we are hitting this error no matter what ever modification we change in settings.py to avoid this error. Tried a lot of Google search results to address this issue, but no luck so far. We are wondering whether anyone has any recommendations on this error. If you did not try Digital Oceanś app platform, what would be your recommendation for production server deployment? We are planning to use only app platforms to avoid infrastructure overhead. > [2023-12-17 01:40:06] │ -> $ python manage.py collectstatic --noinput > [2023-12-17 01:40:06] │Traceback (most recent call last): > [2023-12-17 01:40:06] │ File "/workspace/manage.py", line 23, in > > [2023-12-17 01:40:06] │execute_from_command_line(sys.argv) > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", > line 446, in execute_from_command_line > [2023-12-17 01:40:06] │utility.execute() > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/core/management/__init__.py", > line 420, in execute > [2023-12-17 01:40:06] │django.setup() > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/__init__.py", line > 24, in setup > [2023-12-17 01:40:06] │apps.populate(settings.INSTALLED_APPS) > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/apps/registry.py", > line 91, in populate > [2023-12-17 01:40:06] │app_config = AppConfig.create(entry) > [2023-12-17 01:40:06] │ ^^^ > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/apps/config.py", > line 228, in create > [2023-12-17 01:40:06] │import_module(entry) > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/importlib/__init__.py", line 126, in > import_module > [2023-12-17 01:40:06] │return > _bootstrap._gcd_import(name[level:], package, level) > [2023-12-17 01:40:06] │ > > [2023-12-17 01:40:06] │ File "", > line 1204, in _gcd_import > [2023-12-17 01:40:06] │ File "", > line 1176, in _find_and_load > [2023-12-17 01:40:06] │ File "", > line 1147, in _find_and_load_unlocked > [2023-12-17 01:40:06] │ File "", > line 690, in _load_unlocked > [2023-12-17 01:40:06] │ File " importlib._bootstrap_external>", line 940, in exec_module > [2023-12-17 01:40:06] │ File "", > line 241, in _call_with_frames_removed > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/__init__.py", > line 1, in > [2023-12-17 01:40:06] │from .columns import ( > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/columns/__init__.py", > line 8, in > [2023-12-17 01:40:06] │from .jsoncolumn import JSONColumn > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django_tables2/columns/jsoncolumn.py", > line 11, in > [2023-12-17 01:40:06] │from django.contrib.postgres.fields > import HStoreField > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/fields/__init__.py", > line 1, in > [2023-12-17 01:40:06] │from .array import * # NOQA > [2023-12-17 01:40:06] │ > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/fields/array.py", > line 3, in > [2023-12-17 01:40:06] │from django.contrib.postgres import > lookups > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/lookups.py", > line 4, in > [2023-12-17 01:40:06] │from .search import SearchVector, > SearchVectorExact, SearchVectorField > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/django/contrib/postgres/search.py", > line 1, in > [2023-12-17 01:40:06] │import psycopg2 > [2023-12-17 01:40:06] │ File > "/app/.heroku/python/lib/python3.11/site-packages/psycopg2/__init__.py", > line 51, in > [2023-12-17 01:40:06] │from psycopg2._psycopg import ( > # noqa > [2023-12-17 01:40:06] │SystemError: initialization of _psycopg > raised unreported exception > [2023-12-17 01:40:06] │ > [2023-12-17 01:40:06] │ ! Error while running '$ python manage.py > collectstatic --noinput'. > [2023-12-17 01:40:06] │
Re: Help with DRF error
On Sat, Dec 16, 2023 at 1:10 PM Reddy Tintaya wrote: > Can't you just use > workitem = serializers.PrimaryKeyRelatedField( > queryset=WorkItem.objects.all()) > instead of workitem_id? > No because workitem_id is what is sent in the request. > > On Sat, Dec 16, 2023 at 10:00 AM Larry Martell > wrote: > >> I have a DRF API. It is throwing an error that I have not been able to >> fix. >> >> Here is my view and serializer: >> >> class CreateNotations(CreateAPIView): >> permission_classes = [IsAuthenticated] >> serializer_class = NotationListSerializer >> >> def post(self, request, *args, **kwargs): >> return super().post(request, *args, **kwargs) >> >> class NotationListSerializer(serializers.Serializer): >> workitem_id = >> serializers.PrimaryKeyRelatedField(queryset=WorkItem.objects.all(), >> source="workitem") >> notations = NotationSerializer(many=True) >> >> def create(self, validated_data): >> workitem = validated_data["workitem"] >> >> IncompleteAnalysis.objects.filter(workitem=workitem).delete() >> >> data = [] >> for notation in validated_data["notations"]: >> data.append({ >> 'workitem': workitem, >> 'incomplete_analysis_reason': notation["reason"], >> 'vessel_affected': notation["vessel"], >> 'user': self.context['request'].user, >> 'timestamp': datetime.now().isoformat() >> }) >> >> return >> IncompleteAnalysis.objects.bulk_create([IncompleteAnalysis(**d) for d in >> data]) >> >> The body of the request received is: >> >> {'workitem_id': 244, 'notations': [{'reason_id": 4, 'vessel_id': 6}]} >> >> It fails with this: >> >> AttributeError: Got AttributeError when attempting to get a value for >> field `workitem_id` on serializer `NotationListSerializer`. >> The serializer field might be named incorrectly and not match any >> attribute or key on the `list` instance. >> Original exception text was: 'list' object has no attribute 'workitem'. >> >> Here is the stack trace: >> >> ERRORdjango.request:log.py:241 Internal Server Error: /api/notations/ >> Traceback (most recent call last): >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", >> line 446, in get_attribute >> return get_attribute(instance, self.source_attrs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", >> line 96, in get_attribute >> instance = getattr(instance, attr) >> AttributeError: 'list' object has no attribute 'workitem' >> >> During handling of the above exception, another exception occurred: >> >> Traceback (most recent call last): >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", >> line 56, in inner >> response = get_response(request) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/base.py", >> line 197, in _get_response >> response = wrapped_callback(request, *callback_args, >> **callback_kwargs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/decorators/csrf.py", >> line 55, in wrapped_view >> return view_func(*args, **kwargs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/generic/base.py", >> line 103, in view >> return self.dispatch(request, *args, **kwargs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", >> line 509, in dispatch >> response = self.handle_exception(exc) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", >> line 469, in handle_exception >> self.raise_uncaught_exception(exc) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", >> line 480, in raise_uncaught_exception >> raise exc >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", >> line 506, in dispatch >> response = handler(request, *args, **kwargs) >> File "/inst/martell/EVServer/app/CAPgraph/createevapi/views.py", line >> 1270, in post >> return super().post(request, *args, **kwargs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/generics.py", >> line 190, in post >> return self.create(request, *args, **kwargs) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/mixins.py", >> line 20, in create >> headers = self.get_success_headers(serializer.data) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", >> line 555, in data >> ret = super().data >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", >> line 253, in data >> self._data = self.to_representation(self.instance) >> File >> "/home/larrymartell/.local/lib/python3.8/site-packages/r
Re: Help with DRF error
Can't you just use workitem = serializers.PrimaryKeyRelatedField( queryset=WorkItem.objects.all()) instead of workitem_id? On Sat, Dec 16, 2023 at 10:00 AM Larry Martell wrote: > I have a DRF API. It is throwing an error that I have not been able to fix. > > Here is my view and serializer: > > class CreateNotations(CreateAPIView): > permission_classes = [IsAuthenticated] > serializer_class = NotationListSerializer > > def post(self, request, *args, **kwargs): > return super().post(request, *args, **kwargs) > > class NotationListSerializer(serializers.Serializer): > workitem_id = > serializers.PrimaryKeyRelatedField(queryset=WorkItem.objects.all(), > source="workitem") > notations = NotationSerializer(many=True) > > def create(self, validated_data): > workitem = validated_data["workitem"] > > IncompleteAnalysis.objects.filter(workitem=workitem).delete() > > data = [] > for notation in validated_data["notations"]: > data.append({ > 'workitem': workitem, > 'incomplete_analysis_reason': notation["reason"], > 'vessel_affected': notation["vessel"], > 'user': self.context['request'].user, > 'timestamp': datetime.now().isoformat() > }) > > return > IncompleteAnalysis.objects.bulk_create([IncompleteAnalysis(**d) for d in > data]) > > The body of the request received is: > > {'workitem_id': 244, 'notations': [{'reason_id": 4, 'vessel_id': 6}]} > > It fails with this: > > AttributeError: Got AttributeError when attempting to get a value for > field `workitem_id` on serializer `NotationListSerializer`. > The serializer field might be named incorrectly and not match any > attribute or key on the `list` instance. > Original exception text was: 'list' object has no attribute 'workitem'. > > Here is the stack trace: > > ERRORdjango.request:log.py:241 Internal Server Error: /api/notations/ > Traceback (most recent call last): > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", > line 446, in get_attribute > return get_attribute(instance, self.source_attrs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", > line 96, in get_attribute > instance = getattr(instance, attr) > AttributeError: 'list' object has no attribute 'workitem' > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File > "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", > line 56, in inner > response = get_response(request) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/base.py", > line 197, in _get_response > response = wrapped_callback(request, *callback_args, **callback_kwargs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/decorators/csrf.py", > line 55, in wrapped_view > return view_func(*args, **kwargs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/generic/base.py", > line 103, in view > return self.dispatch(request, *args, **kwargs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", > line 509, in dispatch > response = self.handle_exception(exc) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", > line 469, in handle_exception > self.raise_uncaught_exception(exc) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", > line 480, in raise_uncaught_exception > raise exc > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", > line 506, in dispatch > response = handler(request, *args, **kwargs) > File "/inst/martell/EVServer/app/CAPgraph/createevapi/views.py", line > 1270, in post > return super().post(request, *args, **kwargs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/generics.py", > line 190, in post > return self.create(request, *args, **kwargs) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/mixins.py", > line 20, in create > headers = self.get_success_headers(serializer.data) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", > line 555, in data > ret = super().data > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", > line 253, in data > self._data = self.to_representation(self.instance) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", > line 509, in to_representation > attribute = field.get_attribute(instance) > File > "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/relations.py", > line 190, in get_attribute > return sup
Help with DRF error
I have a DRF API. It is throwing an error that I have not been able to fix. Here is my view and serializer: class CreateNotations(CreateAPIView): permission_classes = [IsAuthenticated] serializer_class = NotationListSerializer def post(self, request, *args, **kwargs): return super().post(request, *args, **kwargs) class NotationListSerializer(serializers.Serializer): workitem_id = serializers.PrimaryKeyRelatedField(queryset=WorkItem.objects.all(), source="workitem") notations = NotationSerializer(many=True) def create(self, validated_data): workitem = validated_data["workitem"] IncompleteAnalysis.objects.filter(workitem=workitem).delete() data = [] for notation in validated_data["notations"]: data.append({ 'workitem': workitem, 'incomplete_analysis_reason': notation["reason"], 'vessel_affected': notation["vessel"], 'user': self.context['request'].user, 'timestamp': datetime.now().isoformat() }) return IncompleteAnalysis.objects.bulk_create([IncompleteAnalysis(**d) for d in data]) The body of the request received is: {'workitem_id': 244, 'notations': [{'reason_id": 4, 'vessel_id': 6}]} It fails with this: AttributeError: Got AttributeError when attempting to get a value for field `workitem_id` on serializer `NotationListSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `list` instance. Original exception text was: 'list' object has no attribute 'workitem'. Here is the stack trace: ERRORdjango.request:log.py:241 Internal Server Error: /api/notations/ Traceback (most recent call last): File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", line 446, in get_attribute return get_attribute(instance, self.source_attrs) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", line 96, in get_attribute instance = getattr(instance, attr) AttributeError: 'list' object has no attribute 'workitem' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 56, in inner response = get_response(request) File "/home/larrymartell/.local/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 55, in wrapped_view return view_func(*args, **kwargs) File "/home/larrymartell/.local/lib/python3.8/site-packages/django/views/generic/base.py", line 103, in view return self.dispatch(request, *args, **kwargs) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch response = self.handle_exception(exc) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception self.raise_uncaught_exception(exc) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception raise exc File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch response = handler(request, *args, **kwargs) File "/inst/martell/EVServer/app/CAPgraph/createevapi/views.py", line 1270, in post return super().post(request, *args, **kwargs) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/generics.py", line 190, in post return self.create(request, *args, **kwargs) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/mixins.py", line 20, in create headers = self.get_success_headers(serializer.data) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", line 555, in data ret = super().data File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", line 253, in data self._data = self.to_representation(self.instance) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/serializers.py", line 509, in to_representation attribute = field.get_attribute(instance) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/relations.py", line 190, in get_attribute return super().get_attribute(instance) File "/home/larrymartell/.local/lib/python3.8/site-packages/rest_framework/fields.py", line 479, in get_attribute raise type(exc)(msg) AttributeError: Got AttributeError when attempting to get a value for field `workitem_id` on serializer `NotationListSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `list` instance. Original