diff --git a/marshmallow/schema.py b/marshmallow/schema.py
index 4de0a123..7fe1289f 100644
--- a/marshmallow/schema.py
+++ b/marshmallow/schema.py
@@ -699,8 +699,8 @@ class BaseSchema(base.SchemaABC):
         """
         if obj and many:
             try:  # Homogeneous collection
-                obj_prototype = obj[0]
-            except IndexError:  # Nothing to serialize
+                obj_prototype = next(iter(obj))
+            except StopIteration:  # Nothing to serialize
                 return self.declared_fields
             obj = obj_prototype
         ret = self.dict_class()

fields.Nested does not support sets
Currently `fields.Nested` assumes that the value of the field is a list - https://github.com/marshmallow-code/marshmallow/blob/dev/marshmallow/schema.py#L702 - and fails for `set` during serialization
diff --git a/tests/test_schema.py b/tests/test_schema.py
index 29dada19..5d0dbbdf 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -3,6 +3,7 @@
 
 import json
 import random
+from collections import namedtuple
 
 import pytest
 
@@ -687,6 +688,21 @@ def test_nested_only_and_exclude():
     assert 'bar' not in result.data['inner']
 
 
+def test_nested_with_sets():
+    class Inner(Schema):
+        foo = fields.Field()
+
+    class Outer(Schema):
+        inners = fields.Nested(Inner, many=True)
+
+    sch = Outer()
+
+    DataClass = namedtuple('DataClass', ['foo'])
+    data = dict(inners=set([DataClass(42), DataClass(2)]))
+    result = sch.dump(data)
+    assert len(result.data['inners']) == 2
+
+
 def test_meta_serializer_fields():
     u = User("John", age=42.3, email="john@example.com",
              homepage="http://john.com")

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
3.9
dev-requirements.txt docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster @ git+https://github.com/sloria/alabaster.git@667b1b676c6bf7226db057f098ec826d84d3ae40
babel==2.17.0
cachetools==5.5.2
certifi==2025.1.31
chardet==5.2.0
charset-normalizer==3.4.1
colorama==0.4.6
distlib==0.3.9
docutils==0.20.1
exceptiongroup==1.2.2
filelock==3.18.0
flake8==2.4.0
idna==3.10
imagesize==1.4.1
importlib_metadata==8.6.1
iniconfig==2.1.0
invoke==2.2.0
Jinja2==3.1.6
MarkupSafe==3.0.2
-e git+https://github.com/marshmallow-code/marshmallow.git@4e922445601219dc6bfe014d36b3c61d9528e2ad#egg=marshmallow
mccabe==0.3.1
packaging==24.2
pep8==1.5.7
platformdirs==4.3.7
pluggy==1.5.0
pyflakes==0.8.1
Pygments==2.19.1
pyproject-api==1.9.0
pytest==8.3.5
python-dateutil==2.9.0.post0
pytz==2025.2
requests==2.32.3
six==1.17.0
snowballstemmer==2.2.0
Sphinx==7.2.6
sphinx-issues==0.2.0
sphinxcontrib-applehelp==2.0.0
sphinxcontrib-devhelp==2.0.0
sphinxcontrib-htmlhelp==2.1.0
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
tomli==2.2.1
tox==4.25.0
typing_extensions==4.13.0
urllib3==2.3.0
virtualenv==20.29.3
zipp==3.21.0

name: marshmallow
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.11+sloria0
      - babel==2.17.0
      - cachetools==5.5.2
      - certifi==2025.1.31
      - chardet==5.2.0
      - charset-normalizer==3.4.1
      - colorama==0.4.6
      - distlib==0.3.9
      - docutils==0.20.1
      - exceptiongroup==1.2.2
      - filelock==3.18.0
      - flake8==2.4.0
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - invoke==2.2.0
      - jinja2==3.1.6
      - markupsafe==3.0.2
      - mccabe==0.3.1
      - packaging==24.2
      - pep8==1.5.7
      - platformdirs==4.3.7
      - pluggy==1.5.0
      - pyflakes==0.8.1
      - pygments==2.19.1
      - pyproject-api==1.9.0
      - pytest==8.3.5
      - python-dateutil==2.9.0.post0
      - pytz==2025.2
      - requests==2.32.3
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==7.2.6
      - sphinx-issues==0.2.0
      - sphinxcontrib-applehelp==2.0.0
      - sphinxcontrib-devhelp==2.0.0
      - sphinxcontrib-htmlhelp==2.1.0
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-qthelp==2.0.0
      - sphinxcontrib-serializinghtml==2.0.0
      - tomli==2.2.1
      - tox==4.25.0
      - typing-extensions==4.13.0
      - urllib3==2.3.0
      - virtualenv==20.29.3
      - zipp==3.21.0
prefix: /opt/conda/envs/marshmallow

tests/test_schema.py::test_nested_with_sets
tests/test_schema.py::test_serializing_basic_object[UserSchema] tests/test_schema.py::test_serializing_basic_object[UserMetaSchema] tests/test_schema.py::test_serializer_dump tests/test_schema.py::test_dump_returns_dict_of_errors tests/test_schema.py::test_dump_with_strict_mode_raises_error[UserSchema] tests/test_schema.py::test_dump_with_strict_mode_raises_error[UserMetaSchema] tests/test_schema.py::test_dump_resets_errors tests/test_schema.py::test_load_resets_errors tests/test_schema.py::test_dump_resets_error_fields tests/test_schema.py::test_load_resets_error_fields tests/test_schema.py::test_errored_fields_do_not_appear_in_output tests/test_schema.py::test_load_many_stores_error_indices tests/test_schema.py::test_dump_many tests/test_schema.py::test_multiple_errors_can_be_stored_for_a_given_index tests/test_schema.py::test_dump_many_stores_error_indices tests/test_schema.py::test_dump_many_doesnt_stores_error_indices_when_index_errors_is_false tests/test_schema.py::test_dump_returns_a_marshalresult tests/test_schema.py::test_dumps_returns_a_marshalresult tests/test_schema.py::test_dumping_single_object_with_collection_schema tests/test_schema.py::test_loading_single_object_with_collection_schema tests/test_schema.py::test_dumps_many tests/test_schema.py::test_load_returns_an_unmarshalresult tests/test_schema.py::test_load_many tests/test_schema.py::test_loads_returns_an_unmarshalresult tests/test_schema.py::test_loads_many tests/test_schema.py::test_loads_deserializes_from_json tests/test_schema.py::test_serializing_none tests/test_schema.py::test_default_many_symmetry tests/test_schema.py::TestValidate::test_validate_returns_errors_dict tests/test_schema.py::TestValidate::test_validate_many tests/test_schema.py::TestValidate::test_validate_many_doesnt_store_index_if_index_errors_option_is_false tests/test_schema.py::TestValidate::test_validate_strict tests/test_schema.py::TestValidate::test_validate_required tests/test_schema.py::test_fields_are_not_copies[UserSchema] tests/test_schema.py::test_fields_are_not_copies[UserMetaSchema] tests/test_schema.py::test_dumps_returns_json tests/test_schema.py::test_naive_datetime_field tests/test_schema.py::test_datetime_formatted_field tests/test_schema.py::test_datetime_iso_field tests/test_schema.py::test_tz_datetime_field tests/test_schema.py::test_local_datetime_field tests/test_schema.py::test_class_variable tests/test_schema.py::test_serialize_many[UserSchema] tests/test_schema.py::test_serialize_many[UserMetaSchema] tests/test_schema.py::test_inheriting_schema tests/test_schema.py::test_custom_field tests/test_schema.py::test_url_field tests/test_schema.py::test_relative_url_field tests/test_schema.py::test_stores_invalid_url_error[UserSchema] tests/test_schema.py::test_stores_invalid_url_error[UserMetaSchema] tests/test_schema.py::test_email_field[UserSchema] tests/test_schema.py::test_email_field[UserMetaSchema] tests/test_schema.py::test_stored_invalid_email tests/test_schema.py::test_integer_field tests/test_schema.py::test_fixed_field tests/test_schema.py::test_as_string tests/test_schema.py::test_decimal_field tests/test_schema.py::test_price_field tests/test_schema.py::test_extra tests/test_schema.py::test_extra_many tests/test_schema.py::test_method_field[UserSchema] tests/test_schema.py::test_method_field[UserMetaSchema] tests/test_schema.py::test_function_field tests/test_schema.py::test_prefix[UserSchema] tests/test_schema.py::test_prefix[UserMetaSchema] tests/test_schema.py::test_fields_must_be_declared_as_instances tests/test_schema.py::test_serializing_generator[UserSchema] tests/test_schema.py::test_serializing_generator[UserMetaSchema] tests/test_schema.py::test_serializing_empty_list_returns_empty_list tests/test_schema.py::test_serializing_dict tests/test_schema.py::test_serializing_dict_with_meta_fields tests/test_schema.py::test_exclude_in_init[UserSchema] tests/test_schema.py::test_exclude_in_init[UserMetaSchema] tests/test_schema.py::test_only_in_init[UserSchema] tests/test_schema.py::test_only_in_init[UserMetaSchema] tests/test_schema.py::test_invalid_only_param tests/test_schema.py::test_can_serialize_uuid tests/test_schema.py::test_can_serialize_time tests/test_schema.py::test_invalid_time tests/test_schema.py::test_invalid_date tests/test_schema.py::test_invalid_email tests/test_schema.py::test_invalid_url tests/test_schema.py::test_invalid_selection tests/test_schema.py::test_custom_json tests/test_schema.py::test_custom_error_message tests/test_schema.py::test_load_errors_with_many tests/test_schema.py::test_error_raised_if_fields_option_is_not_list tests/test_schema.py::test_error_raised_if_additional_option_is_not_list tests/test_schema.py::test_only_and_exclude tests/test_schema.py::test_only_with_invalid_attribute tests/test_schema.py::test_nested_only_and_exclude tests/test_schema.py::test_meta_serializer_fields tests/test_schema.py::test_meta_fields_mapping tests/test_schema.py::test_meta_field_not_on_obj_raises_attribute_error tests/test_schema.py::test_exclude_fields tests/test_schema.py::test_fields_option_must_be_list_or_tuple tests/test_schema.py::test_exclude_option_must_be_list_or_tuple tests/test_schema.py::test_dateformat_option tests/test_schema.py::test_default_dateformat tests/test_schema.py::test_inherit_meta tests/test_schema.py::test_inherit_meta_override tests/test_schema.py::test_additional tests/test_schema.py::test_cant_set_both_additional_and_fields tests/test_schema.py::test_serializing_none_meta tests/test_schema.py::TestErrorHandler::test_dump_with_custom_error_handler tests/test_schema.py::TestErrorHandler::test_load_with_custom_error_handler tests/test_schema.py::TestErrorHandler::test_validate_with_custom_error_handler tests/test_schema.py::TestErrorHandler::test_multiple_serializers_with_same_error_handler tests/test_schema.py::TestErrorHandler::test_setting_error_handler_class_attribute tests/test_schema.py::TestSchemaValidator::test_validator_decorator_is_deprecated tests/test_schema.py::TestSchemaValidator::test_validator_defined_on_class tests/test_schema.py::TestSchemaValidator::test_validator_that_raises_error_with_dict tests/test_schema.py::TestSchemaValidator::test_validator_that_raises_error_with_list tests/test_schema.py::TestSchemaValidator::test_mixed_schema_validators tests/test_schema.py::TestSchemaValidator::test_registered_validators_are_not_shared_with_ancestors tests/test_schema.py::TestSchemaValidator::test_registered_validators_are_not_shared_with_children tests/test_schema.py::TestSchemaValidator::test_inheriting_then_registering_validator tests/test_schema.py::TestSchemaValidator::test_multiple_schema_errors_can_be_stored tests/test_schema.py::TestSchemaValidator::test_schema_validation_error_with_stict_stores_correct_field_name tests/test_schema.py::TestSchemaValidator::test_schema_validation_error_with_strict_when_field_is_specified tests/test_schema.py::TestSchemaValidator::test_schema_validation_error_stored_on_multiple_fields tests/test_schema.py::TestSchemaValidator::test_validator_with_strict tests/test_schema.py::TestSchemaValidator::test_validator_defined_by_decorator tests/test_schema.py::TestSchemaValidator::test_validators_are_inherited tests/test_schema.py::TestSchemaValidator::test_uncaught_validation_errors_are_stored tests/test_schema.py::TestSchemaValidator::test_validation_error_with_error_parameter tests/test_schema.py::TestSchemaValidator::test_store_schema_validation_errors_on_specified_field tests/test_schema.py::TestSchemaValidator::test_errors_are_cleared_on_load tests/test_schema.py::TestSchemaValidator::test_errors_are_cleared_after_loading_collection tests/test_schema.py::TestSchemaValidator::test_raises_error_with_list tests/test_schema.py::TestSchemaValidator::test_raises_error_with_dict tests/test_schema.py::TestSchemaValidator::test_nested_schema_validators tests/test_schema.py::TestPreprocessors::test_preprocessor_decorator_is_deprecated tests/test_schema.py::TestPreprocessors::test_preprocessors_defined_on_class tests/test_schema.py::TestPreprocessors::test_registered_preprocessors_are_not_shared_with_ancestors tests/test_schema.py::TestPreprocessors::test_registered_preprocessors_are_not_shared_with_children tests/test_schema.py::TestPreprocessors::test_preprocessors_defined_by_decorator tests/test_schema.py::TestDataHandler::test_data_handler_is_deprecated tests/test_schema.py::TestDataHandler::test_schema_with_custom_data_handler tests/test_schema.py::TestDataHandler::test_registered_data_handlers_are_not_shared_with_ancestors tests/test_schema.py::TestDataHandler::test_registered_data_handlers_are_not_shared_with_children tests/test_schema.py::TestDataHandler::test_serializer_with_multiple_data_handlers tests/test_schema.py::TestDataHandler::test_setting_data_handlers_class_attribute tests/test_schema.py::TestDataHandler::test_root_data_handler tests/test_schema.py::test_schema_repr tests/test_schema.py::TestNestedSchema::test_flat_nested tests/test_schema.py::TestNestedSchema::test_nested_many_with_missing_attribute tests/test_schema.py::TestNestedSchema::test_nested_with_attribute_none tests/test_schema.py::TestNestedSchema::test_flat_nested2 tests/test_schema.py::TestNestedSchema::test_nested_field_does_not_validate_required tests/test_schema.py::TestNestedSchema::test_nested_none tests/test_schema.py::TestNestedSchema::test_nested tests/test_schema.py::TestNestedSchema::test_nested_many_fields tests/test_schema.py::TestNestedSchema::test_nested_meta_many tests/test_schema.py::TestNestedSchema::test_nested_only tests/test_schema.py::TestNestedSchema::test_exclude tests/test_schema.py::TestNestedSchema::test_list_field tests/test_schema.py::TestNestedSchema::test_list_field_parent tests/test_schema.py::TestNestedSchema::test_nested_load_many tests/test_schema.py::TestNestedSchema::test_nested_errors tests/test_schema.py::TestNestedSchema::test_nested_strict tests/test_schema.py::TestNestedSchema::test_nested_method_field tests/test_schema.py::TestNestedSchema::test_nested_function_field tests/test_schema.py::TestNestedSchema::test_nested_prefixed_field tests/test_schema.py::TestNestedSchema::test_nested_prefixed_many_field tests/test_schema.py::TestNestedSchema::test_invalid_float_field tests/test_schema.py::TestNestedSchema::test_serializer_meta_with_nested_fields tests/test_schema.py::TestNestedSchema::test_serializer_with_nested_meta_fields tests/test_schema.py::TestNestedSchema::test_nested_fields_must_be_passed_a_serializer tests/test_schema.py::TestNestedSchema::test_invalid_type_passed_to_nested_many_field tests/test_schema.py::TestSelfReference::test_nesting_schema_within_itself tests/test_schema.py::TestSelfReference::test_nesting_schema_by_passing_class_name tests/test_schema.py::TestSelfReference::test_nesting_within_itself_meta tests/test_schema.py::TestSelfReference::test_nested_self_with_only_param tests/test_schema.py::TestSelfReference::test_multiple_nested_self_fields tests/test_schema.py::TestSelfReference::test_nested_many tests/test_schema.py::test_serialization_with_required_field tests/test_schema.py::test_deserialization_with_required_field tests/test_schema.py::test_deserialization_with_required_field_and_custom_validator tests/test_schema.py::TestContext::test_context_method tests/test_schema.py::TestContext::test_context_method_function tests/test_schema.py::TestContext::test_function_field_raises_error_when_context_not_available tests/test_schema.py::TestContext::test_fields_context tests/test_schema.py::TestContext::test_nested_fields_inherit_context tests/test_schema.py::test_serializer_can_specify_nested_object_as_attribute tests/test_schema.py::TestFieldInheritance::test_inherit_fields_from_schema_subclass tests/test_schema.py::TestFieldInheritance::test_inherit_fields_from_non_schema_subclass tests/test_schema.py::TestFieldInheritance::test_inheritance_follows_mro tests/test_schema.py::TestAccessor::test_accessor_is_used tests/test_schema.py::TestAccessor::test_accessor_with_many tests/test_schema.py::TestAccessor::test_accessor_decorator tests/test_schema.py::TestRequiredFields::test_required_string_field_missing tests/test_schema.py::TestRequiredFields::test_required_string_field_failure tests/test_schema.py::TestRequiredFields::test_allow_none_param tests/test_schema.py::TestRequiredFields::test_allow_none_custom_message tests/test_schema.py::TestDefaults::test_missing_inputs_are_excluded_from_dump_output tests/test_schema.py::TestDefaults::test_none_is_serialized_to_none tests/test_schema.py::TestDefaults::test_default_and_value_missing tests/test_schema.py::TestDefaults::test_loading_none tests/test_schema.py::TestDefaults::test_missing_inputs_are_excluded_from_load_output
marshmallow/schema.py
marshmallow/schema.py